eslint-plugin-node icon indicating copy to clipboard operation
eslint-plugin-node copied to clipboard

no-missing-require: support package.json exports field

Open kevinoid opened this issue 4 years ago • 2 comments

If a script requires a name exported using the package.json "exports" field, it causes the node/no-missing-require rule to fail. For example:

npm install yargs eslint eslint-plugin-node
echo '{"extends":["plugin:node/recommended"]}' > .eslintrc.json
echo "const Yargs = require('yargs/yargs');" > index.js
./node_modules/.bin/eslint index.js

will print

/tmp/path/index.js
  1:23  error  "yargs/yargs" is not found  node/no-missing-require

✖ 1 problem (1 error, 0 warnings)

even though ./yargs is declared in the "exports" field of yargs/package.json and index.js executes without error.

Thanks for considering, Kevin

kevinoid avatar Sep 09 '20 22:09 kevinoid

If it can save someone's time who would have wished to fix this...

  • Fix PR (work in progress)
  • Related: #255

cdoublev avatar Mar 07 '21 09:03 cdoublev

There can be also imports field in package.json which can be used for mappings.

"imports": {
    "#abc/*": "./abc/out/*"
  }
require('#abc/file')

david-bojnansky avatar Nov 17 '21 06:11 david-bojnansky