nodeenv
nodeenv copied to clipboard
ERR_MODULE_NOT_FOUND when using imports in an eslint config file
Hi,
I've been encountering a strange error when using eslint and I think (not 100% sure) that the issue might come from nodeenv.
I originally encountered the problem while using pre-commit (which uses nodeenv internally) but I was able to trim down the setup to a single file:
- Create a new virtual environment:
nodeenv env - Activate it:
. env/bin/activate - Install
eslintandglobals(globally):npm install -g eslint globals - Create a config file for eslint:
echo 'import globals from "globals"; export default [{languageOptions: { globals: globals.browser }}];' > eslint.config.mjs - Run eslint:
eslint .
On my computer, this results in a crash with the following error:
Oops! Something went wrong! :(
ESLint: 9.2.0
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'globals' imported from /path/to/project/eslint.config.mjs
Did you mean to import "globals/index.js"?
at packageResolve (node:internal/modules/esm/resolve:845:9)
at moduleResolve (node:internal/modules/esm/resolve:918:18)
at defaultResolve (node:internal/modules/esm/resolve:1148:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:541:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:510:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)
As a workaround, I can make the error go away by installing globals locally: npm install globals (with the virtual environment still active). After that running eslint . doesn't crash anymore.
Is there something that nodeenv is not handling correctly here, or is the issue somewhere further down the line?
Thanks! ✨
I think this is a behaviour change in ESLint 9, it happens under npx without using nodeenv. I made a report on ESLint: https://github.com/eslint/eslint/issues/18465 .