Eslint-plugin-import: [BUG] ESLint crashes with `import/no-unused-modules` and `ignoreExports` option

Created on 14 Apr 2019  路  8Comments  路  Source: benmosher/eslint-plugin-import

ESLint crashes with the following error:

$ eslint .
TypeError: Cannot read property 'get' of undefined
Occurred while linting /home/ehmicky/dir/a.js:1
    at checkExportPresence (/home/ehmicky/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:308:37)
    at Program:exit (/home/ehmicky/node_modules/eslint-plugin-import/lib/rules/no-unused-modules.js:712:9)
    at listeners.(anonymous function).forEach.listener (/home/ehmicky/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/home/ehmicky/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/ehmicky/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/home/ehmicky/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.leaveNode (/home/ehmicky/node_modules/eslint/lib/util/node-event-generator.js:303:14)
    at CodePathAnalyzer.leaveNode (/home/ehmicky/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:654:23)
    at nodeQueue.forEach.traversalInfo (/home/ehmicky/node_modules/eslint/lib/linter.js:770:32)

The current directory contains the following files:

dir/a.js:

import { test } from './b.js'

dir/b.js:

export const test = true

.eslintrc.json:

{
  "parserOptions": {
    "ecmaVersion": 2019,
    "sourceType": "module"
  },
  "plugins": ["import"],
  "rules": {
    "import/no-unused-modules": [
      2,
      {
        "ignoreExports": ["dir/"],
        "unusedExports": true,
        "missingExports": true
      }
    ]
  }
}

package.json (and node_modules):

{
  "name": "unused-modules-bug",
  "version": "1.0.0",
  "dependencies": {},
  "devDependencies": {
    "eslint": "^6.0.0-alpha.0",
    "eslint-plugin-import": "^2.17.1"
  }
}

Thanks for your help!

Most helpful comment

I tried it and it works. Thanks!

All 8 comments

hm, is export test = true even valid JS without a const/let/var keyword?

Oops :) no it's not. I fixed the example. I tried it again and the bug is still reproducible.

(Bug originally happened in a big repository, I tried to reduce it to a minimally reproducible example)

Does this happen in eslint 5, or only in eslint 6 alpha?

It still happens with eslint 5.16.0.

Would you like me to create a demo repository?

Yes, that'd be great, thanks. We already have some test cases for this that seem to be passing, so a repro would be great.

Yes, absolutely. I will do it tomorrow (I am off my laptop for the evening).

No need to create a repository. Your provided source is sufficient to reproduce the issue.

The crash happens when dir/b.js gets linted. As this file is being ignored, no export list has been built up for the file. The problem is, that the rule still tries to read the export list for this file instead of ignoring the file.

1331 should fix this issue.

I tried it and it works. Thanks!

Was this page helpful?
0 / 5 - 0 ratings