eslint-plugin-node
eslint-plugin-node copied to clipboard
no-missing-require: support package.json exports field
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
If it can save someone's time who would have wished to fix this...
- Fix PR (work in progress)
- Related: #255
There can be also imports field in package.json which can be used for mappings.
"imports": {
"#abc/*": "./abc/out/*"
}
require('#abc/file')