Hi, I'm using the eslint-plugin-import along with eslint in a project which as this folder structure:
project_root/
|_ server/
|_ src/
|_ .eslintrc
|_ client/
|_ src/
|_ .eslintrc
|_ tools
|_ webpack.config.js
I have defined some aliases in webpack like so:
/* client/webpack.config.js */
config = {
resolve: {
alias: {
Common: path.resolve('src/common'),
IP: path.resolve('src/apps/inv-planner'),
},
modules: ['node_modules', 'src'],
extensions: ['.js'],
},
}
This is my relevant eslint config:
settings: {
'import/resolver': {
node: {
moduleDirectory: ['node_modules', 'src'],
},
webpack: {
config: `${__dirname}/tools/webpack.config.js`, // vscode doesn't resolve this
// config: `./tools/webpack.config.js`, // vscode doesn't resolve this either
},
},
},
I have opened the project_root folder in vscode, and all eslint rules work fine in VSCode, except for import/extensions, which keeps throwing errors for imports from the src/apps/inv-planner directory, but not from the src/common directory.
import AsyncRequests from 'IP/components/AsyncRequests'; // throws error
import Instrumentation from 'Common/extensions/instrumentation'; // doesn't throw
The eslint CLI works fine, but the vscode extension doesn't. Is there an issue in path resolution for non-root directories in this plugin?
I am pretty sure that the eslint.workingDirectories setting is your friend. You even might to set "changeProcessCWD": true. Something like:
"eslint.workingDirectories": [
{ "directory": "./client", "changeProcessCWD": true },
{ "directory": "./server", "changeProcessCWD": true }
]
If this doesn't help please provide me with a GitHub repository I can clone that demos what you are seeing.
Thanks, I'll try it out and report back next week
It works. Thanks.
Most helpful comment
I am pretty sure that the
eslint.workingDirectoriessetting is your friend. You even might to set"changeProcessCWD": true. Something like:If this doesn't help please provide me with a GitHub repository I can clone that demos what you are seeing.