Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_MODULE_NOT_FOUND when using imports in an eslint config file #353

Open
bmispelon opened this issue May 9, 2024 · 1 comment
Open

Comments

@bmispelon
Copy link

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:

  1. Create a new virtual environment: nodeenv env
  2. Activate it: . env/bin/activate
  3. Install eslint and globals (globally): npm install -g eslint globals
  4. Create a config file for eslint: echo 'import globals from "globals"; export default [{languageOptions: { globals: globals.browser }}];' > eslint.config.mjs
  5. 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! ✨

@adamchainz
Copy link
Contributor

I think this is a behaviour change in ESLint 9, it happens under npx without using nodeenv. I made a report on ESLint: eslint/eslint#18465 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants