Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack resolver: config not used if config file requires transpilation #799

Closed
Nilos opened this issue Apr 11, 2017 · 20 comments
Closed

webpack resolver: config not used if config file requires transpilation #799

Nilos opened this issue Apr 11, 2017 · 20 comments

Comments

@Nilos
Copy link

Nilos commented Apr 11, 2017

Hi everyone,

I get a lot of no-unresolved errors when using this with webpack 2.3.3.

Plugins:

"eslint-import-resolver-webpack": "^0.8.1",
"eslint-plugin-import": "^2.2.0",

Webpack resolve config:

resolve: {
  modules: [
    path.join(__dirname, 'src'),
    path.join(__dirname, 'styles'),
    'node_modules'
  ]
},,

Eslintrc:

"settings": {
  "import/resolver": {
    "webpack": {
      "config": "webpack.config-base.js"
    }
  }
}
@jeefuji
Copy link

jeefuji commented Apr 11, 2017

Hello !
Same problem here.

Since I updated from 2.2.1 to 2.3.3, i can't resolve any package from custom paths.

resolve: { alias: config.pack.alias, extensions: ['.js', '.json', '.vue', '.css', '.node', '.ts', '.tsx', '.node'], modules: [ path.resolve(__dirname, 'app/node_modules') ] },

Nothing in app/node_modules is resolved unfortunately.

@paol
Copy link

paol commented May 4, 2017

Same here, I just updated from webpack v1 to latest v2 (2.4.1) and the webpack resolver stopped working.

In webpack.config.js:

  resolve: {
    modules: [
      "node_modules",
      path.resolve('./src')
    ],
    extensions: ['.jsx', '.js']
  }

@lvpro
Copy link

lvpro commented May 23, 2017

Same here. Worked fine with Webpack 1.14.0. Upgraded to Webpack 2.5.1 and the webpack-resolver no longer works. boo.

@vorlov
Copy link

vorlov commented Jun 11, 2017

updated to webpack 2.6.1 and resolver stopped working

.eslintrc

"settings": {
  "import/resolver": {
    "webpack": {
      "config": "webpack.common.config.js"
    }
  }
}

webpack.common.config.js

resolve: {
    extensions: ['.js', '.jsx'],
    alias: {
      containers: path.resolve(ROOT_PATH, './src/containers'),
      components: path.resolve(ROOT_PATH, './src/components'),
      sections: path.resolve(ROOT_PATH, './src/components/ContainerSections'),
      'redux-base': path.resolve(ROOT_PATH, './src/redux-base'),
      utils: path.resolve(ROOT_PATH, './src/utils'),
      common: path.resolve(ROOT_PATH, './src/common'),
      routes: path.resolve(ROOT_PATH, './src/routes'),
      config: path.resolve(ROOT_PATH, './src/config'),
      static: path.resolve(ROOT_PATH, './static'),
      styles: path.resolve(ROOT_PATH, './src/styles'),
    },
  }

@ebramanti
Copy link

Similar config as @vorlov and my resolver is not working either.

@ljharb
Copy link
Member

ljharb commented Jun 20, 2017

"+1s" aren't helpful; please avoid cluttering up issues and instead, react with an emoji on the original post. I'll now delete the +1s.

@import-js import-js deleted a comment from zhenyulin Jun 20, 2017
@import-js import-js deleted a comment from ddaza Jun 20, 2017
@bradennapier
Copy link
Contributor

bradennapier commented Jun 30, 2017

any movement/workaround to this issue? every file in my app fails due to this :(

Severity 	Provider 	Description	Line 
Error	ESLint	Resolve error: Cannot assign to read only property '.js' of object '#<Object>' (import/no-unresolved)	1:1
Error	ESLint	Resolve error: Cannot assign to read only property '.js' of object '#<Object>' (import/no-duplicates)	1:1
Error	ESLint	Resolve error: Cannot assign to read only property '.js' of object '#<Object>' (import/extensions)	1:1
Error	ESLint	Resolve error: Cannot assign to read only property '.js' of object '#<Object>' (import/no-absolute-path)	1:1
Error	ESLint	Resolve error: Cannot assign to read only property '.js' of object '#<Object>' (import/no-named-as-default)	1:1
Error	ESLint	Resolve error: Cannot assign to read only property '.js' of object '#<Object>' (import/no-named-as-default-member)	1:1
Error	ESLint	Unable to resolve path to module 'saga-event-observer'. (import/no-unresolved)	3:31
Error	ESLint	Missing file extension for "saga-event-observer" (import/extensions)	3:31

@lexiv0re
Copy link

@bradennapier the only workaround is to disable these rules in eslint config until the issue will be resolved.

@zhenyulin
Copy link

Mine doesn't work earlier either, and I found out the issue to be I used ES6 syntax import and export in the webpack config file, which isn't loaded by .eslintrc correctly, though babel-eslint has been applied as the parser. I resolved the issue by falling back to use require and module.exports.

HTH.

@r1m
Copy link

r1m commented Oct 19, 2017

Same as @zhenyulin, my webpack config was not used at all.
I replaced all my import/export with require/module.exports in my webpack.config.js and it's now working

"settings": {
    "import/parser": "babel-eslint",
    "import/resolver": {
      "webpack": {
        "config": "./tools/webpack.config.js"
      }
    },

@benmosher benmosher changed the title Resolver not working for webpack 2.3.3 webpack resolver: config not used if config file requires transpilation Oct 20, 2017
@benmosher
Copy link
Member

@r1m: great point! the resolver only transpiles the config if it is named *.babel.js. Does webpack v2+ automatically transpile config?

@benmosher
Copy link
Member

others: webpack 2/3 is supported (I'm using Webpack v3 with an ancient version of the plugin and it works fine) but as @r1m mentioned, if the resolver can't load the config because it has syntax not supported by your local Node version, it won't work unless you rename your config to .babel.js.

Does anyone have a reference to Webpack docs that describe whether/how it supports non-native syntax in config?

@r1m
Copy link

r1m commented Oct 21, 2017

I'm not directly using webpack-cli but using the API, that why I can use import/export. I just realized that.
And you're right, according to Webpack doc, you must you the .babel.js extension. Thanks for pointing this.

Maybe a new feature : add a warning when this plugin cannot read the configFile provided :)

@ghost
Copy link

ghost commented Nov 10, 2017

You can also transpile webpack config from es6 to es5 on the fly with babel-register

my package.json

"babel-preset-env": "^1.3.2",
"babel-register": "^6.26.0",
"eslint": "^4.10.0",
"eslint-import-resolver-webpack": "^0.8.3",
"eslint-plugin-import": "^2.8.0",

.eslintrc.json

"settings": {
  "import/resolver": {
    "webpack": {
      "config": "build/webpack.eslint.conf.js"
    }
  }
},

build/webpack.eslint.conf.js

require('babel-register')({
  presets: ['env'],
}); 

module.exports = require('./webpack.base.conf.js');

@ljharb
Copy link
Member

ljharb commented Nov 10, 2017

or you can just name it webpack.config.babel.js and webpack will do that for you automatically.

@r1m
Copy link

r1m commented Nov 10, 2017

The problem right now is that the plugin is failing silently to parse the config. Solutions exist but it's hard to find the cause in the first place : the only symptom is that eslint will not resolve imports.

The fix would be to document it properly or add a console warning when eslint is loading (don't know if possible)

@ljharb
Copy link
Member

ljharb commented Nov 10, 2017

Some sort of warning or error seems reasonable; I'd be in favor of a hard failure when a config exists but fails to parse.

@spiffcs
Copy link

spiffcs commented Mar 6, 2018

@qawsqs should be the accepted answer (@ljharb is also great if you have the context of the previous answer)

@mvorisek
Copy link

mvorisek commented Nov 25, 2022

I confirm import/extensions rule does not work in vue files.

UPDATE: issue can be probably closed as https://www.npmjs.com/package/eslint-import-resolver-webpack solved the problem for me

@ljharb
Copy link
Member

ljharb commented Nov 26, 2022

Seems like #799 (comment) and eslint-import-resolver-webpack are the solutions here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests