eslint-plugin-unicorn: Error: Failed to load plugin 'eslint-plugin-unicorn' declared in '--config#overrides[2]': Cannot find module 'node:path'

Upgrading eslint-plugin-unicorn from 42.0.0 to 43.0.0 results in the following error:

@:~/> yarn lint
\ Processing: electron/src/preload.ts 

Oops! Something went wrong! :(

ESLint: 8.19.0

Error: Failed to load plugin 'eslint-plugin-unicorn' declared in '--config#overrides[2]': Cannot find module 'node:path'
Require stack:
- /node_modules/eslint-plugin-unicorn/rules/utils/rule.js
- /node_modules/eslint-plugin-unicorn/index.js
- /node_modules/@eslint/eslintrc/dist/eslintrc.cjs
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/node_modules/eslint-plugin-unicorn/rules/utils/rule.js:2:14)
    at Module._compile (/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)

I reverted the version back and it worked

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 34

Most upvoted comments

Closing since we are not going to do anything, please use a Node version that supports require("node:path")

Using Node 16.4.0 and seeing the error:

JSON Decode error: We expected JSON from 'eslint', but instead got this:
Error: Failed to load plugin 'unicorn' declared in '.eslintrc.js': Cannot find module 'node:path'
Require stack:
- /home/me/Documents/MyProject/node_modules/eslint-plugin-unicorn/rules/utils/rule.js
- /home/me/Documents/MyProject/node_modules/eslint-plugin-unicorn/index.js
- /home/me/Documents/MyProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
Referenced from: /home/me/Documents/MyProject/.eslintrc.js

I confirmed node:path is importable in this version by running node -e 'console.log(typeof require("node:path"))' which yields object. What could be the problem?

Edit: Also affects Node 16.17.0, BUT I’ve noticed this issue is only present on Linux - on Windows it works fine. @fisker I think something may indeed need to be done to resolve this. Downgrading to 42.x yields a working ESLint config on all OS.

Node.js document that it’s supported https://nodejs.org/dist/latest-v16.x/docs/api/modules.html#:~:text=Added node: import support to, if you are still facing this issue, please report to Node.js

This is happening because the library was bumped in v43 to require >= Node 14.18, where the node: protocol import syntax was introduced. If this is failing for you (as it is for us) it’s because you’re on an earlier version of Node.

@Slapbox , I am on Mac OS

I don’t really understand the issue here. Is it that hard to setup a reproduction? If many of you already have problems, can you just delete your private stuff and put your code somewhere, so I can debug. I didn’t even ask it has to be minimum.

I am seeing this error when trying to add Typescript to Nuxt, in their documentation you install @nuxtjs/eslint-config-typescript which eslint-plugin-unicorn is a dependancy of https://typescript.nuxtjs.org/guide/lint/, using node v16.17.1 Screenshot 2022-10-05 at 17 09 45

Seeing this error on a fresh oclif generated app after running npm update and manually forcing eslint to upgrade to 8.x. I’m on MacOS running node 16.18.0.

> eslint . --ext .ts --config .eslintrc

Oops! Something went wrong! :(

ESLint: 8.26.0

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Failed to load plugin 'unicorn' declared in '--config » eslint-config-oclif': Package subpath './lib/rules/no-warning-comments' is not defined by "exports" in /Users/MYUSER/MYAPP/node_modules/eslint/package.json

I haven’t dug enough to see if this is just a compatbility issue with the rules in eslint-config-oclif with the latest version of eslint or what. Checking that now.

In your package.json, simply change your versioning to accept upcoming minor & patch updates, that is by having: "version": "2.0.0" instead of "version": "2"

I am actually on node 16 @fisker @erunion . not sure why this issue was closed and noone wanted to check with me which node i am on 😃

rm -rf node_modules && rm package-lock.json && npm i solved it for me

If the Node.js version is the problem, why it’s fine to stay on old Node.js version, but not fine to stay on old unicorn version?

But still, this issue should be open because it’s a real issue.

I’m seeing the same issue, but with a twist. It works on my local dev (Mac) machine, but fails on our CI (Windows) machine.

As can be seen below, it’s running Node 16.

I’m downgrading to version 42 to solve it for now, but wanted to leave this here to help with the root cause investigation.

; node bin location = E:\_work\_tool\node\16.18.1\x64\node.exe
; node version = v16.18.1
; npm local prefix = E:\_work\237\s
; npm version = 8.19.2
; cwd = E:\_work\237\s
; HOME = C:\Windows\ServiceProfiles\NetworkService
; Run `npm config ls -l` to show all defaults.
C:\Windows\system32\cmd.exe /D /S /C "E:\_work\_tool\node\16.18.1\x64\npm.cmd start lint"


Oops! Something went wrong! :(

> nps lint
ESLint: 8.28.0


nps is executing `lint` : nps lint.eslint && nps lint.scss
Error: Failed to load plugin 'unicorn' declared in '.eslintrc.json': Cannot find module 'node:path'
nps is executing `lint.eslint` : eslint --cache "src/**/*.ts" "test/**/*.ts" "*.js" "customplugins/**/*.js"
Require stack:
- E:\_work\237\s\node_modules\eslint-plugin-unicorn\rules\utils\rule.js
- E:\_work\237\s\node_modules\eslint-plugin-unicorn\index.js
- E:\_work\237\s\node_modules\@eslint\eslintrc\dist\eslintrc.cjs
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (E:\_work\237\s\node_modules\eslint-plugin-unicorn\rules\utils\rule.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)

Just my two cents - it seems like all this suffering is not worth using node:* style require statements. We’re still on an older version because of this issue. It really should not be closed as it’s apparent that people whose machines meet the stated package requirements are having trouble with it on multiple machines. @fisker.

Spent a bit of time working around this, but got typescript enabled within our nuxt project without @nuxtjs/eslint-config-typescript.

.eslintrc.js has ->

parserOptions: {
    parser: '@typescript-eslint/parser'
  },

extends: [
    '@nuxtjs',
    'plugin:vue/recommended',
    'plugin:nuxt/recommended',
    'prettier'
  ],

overrides: [
    {
      files: ['*.ts'],
      parser: '@typescript-eslint/parser',
      plugins: ['@typescript-eslint'],
      extends: ['plugin:@typescript-eslint/recommended']
    }
  ],

Since we are migrating from JS to TS we still need to allow both so have this within out tsconfig.json file ->

"allowJs": true,
"noImplicitThis": false,
 "types": ["@types/node", "@nuxt/types"]

Now TS files and vue files with script lang="ts" lint correctly as well as normal vue files.

This is happening because the library was bumped in v43 to require >= Node 14.18, where the node: protocol import syntax was introduced. If this is failing for you (as it is for us) it’s because you’re on an earlier version of Node.

With Node 15.x this problem also occurs 😢