Open dickeylth opened 7 years ago
I have this same problem. It seems as if the webpack import plugin registers after the import plugin has already attempted to resolve some paths. If it attempts to resolve them before the plugin has loaded, they do not resolve.
I am using the eslint plugin in Atom and it actually says there are no errors. But when I run the eslint command from the CLI, it does have these errors. This leads me to believe that the plugin works, but maybe it is not enhancing the resolver in time when running from the CLI?
After more investigation, it seems that running ./node_modules/.bin/eslint filename
actually does work with the webpack resolver. However, setting a script in package.json and running it via yarn run
or npm run
does not work.
In package.json: "scripts": { "lint": "eslint ./app" }
<- yarn run lint
will use ./node_modules/.bin/eslint
but still does not work.
Even explicitly setting the bin in package.json does not work:
In package.json: "scripts": { "lint": "./node_modules/.bin/eslint ./app" }
<- yarn run lint
does not work.
Via yarn run lint
:
Running directly:
~/Projects/beerfeels-client (webpack2 *)$ ./node_modules/.bin/eslint ./app/components/Feel.js
~/Projects/beerfeels-client (webpack2 *)$
That sounds like a bug then - node_modules
should never need to be hardcoded anywhere, especially in package.json.
@ljharb It doesn't need to be hardcoded, it always executes the local eslint bin. It's the fact that the plugin doesn't work because it doesn't resolve modules based on the webpack config either way.
Lint passes: Running ./node_modules/.bin/eslint app
from the terminal
Lint does not pass: Running yarn run lint
with lint
being eslint app
in package.json. It lints, but the webpack module alias resolving does not work, causing lint errors where it should not. All other eslint plugins work.
eslint-plugin-import:resolver:node Resolving: ./test.scss
It's using the default node
resolver for some files. I suspect some other .eslintrc
is getting picked up for some of the files. Strange that .eslintrc
resolution would be different between npm run ..
and Atom/pure ESlint CLI.
I'm guessing Atom also just runs the bin directly. The only thing I know of that yarn/npm run
does is that it adds node_modules/.bin
to $PATH
.
In that case, you should be configuring your Atom to add that to the PATH (or rather it should be doing that for you)
@ljharb it does use the local eslint copy by default, I do not have eslint installed globally.
I'm encountering this issue now:
eslint .
produces tons of errors all related to import/no-unresolved with the Webpack configgrunt eslint
passes (Grunt programatically invokes ESLint)./node_modules/.bin/eslint .
also passesnpm run fix
where the fix
is configured to be eslint . --fix && vendor/bin/php-cs-fixer fix .
npx eslint .
worksAny ideas?
@RinkAttendant6 sounds like which eslint
points to a global install, not a local one. Try npm uninstall -g eslint
.
@ljharb Thank you, it is working fine now! I've updated my comment with some more results.
Is there any reason why it doesn't resolve relative to or based on the local ESLint configuration?
eslint
should only be run via an npm run-script
or npx
; running it by itself doesn't run the local one.
I have the
.eslintrc
under my project:and dependencies:
and I tried
DEBUG=eslint-plugin-import:* grunt eslint
:I've specified
externals: [ 'base' ],
in webpack config, however eslint still throwsError: Cannot find module 'base' from '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home'
;and I've specified
resolve: {alias: { '@mods': 'dir', '@pages': 'dir' } },}
in webpack config, however eslint still throwseslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module '@mods/header/index' from '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail'
Could you help me figure out what's wrong here?