Skip to content

ERR_MODULE_NOT_FOUND when using imports in an eslint config file #353

@bmispelon

Description

@bmispelon

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! ✨

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions