This issue is probably related to #1323. It is slightly different though. It's also using the latest version of eslint-plugin-import, including the fix of #1323.
ESLint crashes with the following error:
$ eslint .
TypeError: Cannot read property 'get' of undefined
Occurred while linting /home/ehmicky/no-unused-modules-bug/file.js:1
at checkUsage (/home/ehmicky/no-unused-modules-bug/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:339:33)
at ExportNamedDeclaration.node.declaration.declarations.forEach.declaration (/home/ehmicky/no-unused-modules-bug/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:732:15)
at Array.forEach (<anonymous>)
at ExportNamedDeclaration (/home/ehmicky/no-unused-modules-bug/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:731:43)
at listeners.(anonymous function).forEach.listener (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/safe-emitter.js:45:58)
at Array.forEach (<anonymous>)
at Object.emit (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/node-event-generator.js:251:26)
at NodeEventGenerator.applySelectors (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/node-event-generator.js:280:22)
at NodeEventGenerator.enterNode (/home/ehmicky/no-unused-modules-bug/node_modules/eslint/lib/util/node-event-generator.js:294:14)
The current directory contains the following files:
src/main.js:
export const main = true
file.js:
export const test = true
.eslintrc.json:
{
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
},
"plugins": ["import"],
"rules": {
"import/no-unused-modules": [
2,
{
"unusedExports": true,
"src": ["src/"]
}
]
}
}
package.json:
{
"name": "no-unused-modules-bug",
"version": "1.0.0",
"dependencies": {},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-plugin-import": "^2.17.2"
}
}
cc @rfermann
@ljharb: thanks for adding. I will tackle this issue after #1339 is solved.
Thanks @rfermann!
I created a demo repo: https://github.com/ehmicky/no-unused-modules-bug-two
I also got this problem. However I didn't need to specify a src option to crash my process, so the default value is enough to reproduce.
My config is:
import/no-unused-modules:
- error
- missingExports: true
unusedExports: true
@dfleury could you share a minimally reproducible example? Including:
Like this the maintainers can make sure your issue is fixed together with mine (if they have the same cause).
The problem was, that there was a file to be linted which was outside the specified src folder. These files should be excluded from being linted by this rule.
@dfleury can you verify that you are linting files outside the src folder (process.cwd() by default)?
This is fixing my problem, thanks!
@dfleury I think this issue should be closed after this PR is merged. If the PR does not solve your issue, then it means it was a separate problem, i.e. should be a separate issue. What do you think?
@ljharb Would it be possible to release a new version? Thanks!
As soon as i have the time :-) it is a weekend, after all.
Absolutely, there is no rush! :)
Thanks for the bug fix.
Yes, I can confirm that's working with this fix.
Sorry by not giving a demo in time. I was having some difficulties to reproduce it without knowing the right conditions to do it since my working project is kinda big to track all possibilities in mind.
Once @rfermann told us the problem, I could reproduce it in my WIP demo.
Thanks @rfermann!
Most helpful comment
Yes, I can confirm that's working with this fix.
Sorry by not giving a demo in time. I was having some difficulties to reproduce it without knowing the right conditions to do it since my working project is kinda big to track all possibilities in mind.
Once @rfermann told us the problem, I could reproduce it in my WIP demo.
Thanks @rfermann!