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

NodeJS 13: Failed to load plugin '@typescript-eslint' #1944

Closed
Ximik opened this issue Apr 27, 2020 · 11 comments
Closed

NodeJS 13: Failed to load plugin '@typescript-eslint' #1944

Ximik opened this issue Apr 27, 2020 · 11 comments
Labels
awaiting response Issues waiting for a reply from the OP or another party package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@Ximik
Copy link

Ximik commented Apr 27, 2020

The eslint stops working after updating from node v12.16.1 to v13.13.0.

.eslintrc.cjs

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: ['./tsconfig.json'],
  },
  plugins: ['@typescript-eslint'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
  ],
  rules: {
  },
};

tsconfig.json

{
  "compilerOptions": {
    "noImplicitAny": true,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "alwaysStrict": true,
    "target": "es6",
    "module": "es6",
    "moduleResolution": "node",
    "declaration": true,
    "outDir": "./lib"
  }
}

package.json

{
  "type": "module",
  "scripts": {
    "lint": "eslint src --ext .ts,.js --fix && tsc --noEmit"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.30.0",
    "@typescript-eslint/parser": "^2.30.0",
    "eslint": "^6.8.0",
    "typescript": "^3.8.3"
  }
}

The output

$ ./node_modules/.bin/eslint src --ext .ts,.js --debug
  eslint:cli CLI args: [ 'src', '--ext', '.ts,.js', '--debug' ] +0ms
  eslint:cli Running on files +3ms
  eslint:config-array-factory Loading JSON config file: /home/alex/tracker/package.json +0ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/home/alex/tracker', loose: false } ] +0ms
  eslint:ignore-pattern   processed: { basePath: '/home/alex/tracker', patterns: [ '/node_modules/*', '/bower_components/*' ] } +1ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/home/alex/tracker', loose: false } ] +1ms
  eslint:ignore-pattern   processed: { basePath: '/home/alex/tracker', patterns: [ '/node_modules/*', '/bower_components/*' ] } +0ms
  eslint:file-enumerator Start to iterate files: [ 'src' ] +0ms
  eslint:file-enumerator Directory: /home/alex/tracker/src +0ms
  eslint:file-enumerator Enter the directory: /home/alex/tracker/src +0ms
  eslint:cascading-config-array-factory Load config files for /home/alex/tracker/src. +0ms
  eslint:cascading-config-array-factory No cache found: /home/alex/tracker/src. +0ms
  eslint:config-array-factory Config file not found on /home/alex/tracker/src +5ms
  eslint:cascading-config-array-factory No cache found: /home/alex/tracker. +0ms
  eslint:config-array-factory Loading JS config file: /home/alex/tracker/.eslintrc.cjs +1ms
  eslint:config-array-factory Config file found: /home/alex/tracker/.eslintrc.cjs +5ms
  eslint:config-array-factory Loading {extends:"eslint:recommended"} relative to /home/alex/tracker/.eslintrc.cjs +1ms
  eslint:config-array-factory Loading JS config file: /home/alex/tracker/node_modules/eslint/conf/eslint-recommended.js +0ms
  eslint:config-array-factory Loading {extends:"plugin:@typescript-eslint/eslint-recommended"} relative to /home/alex/tracker/.eslintrc.cjs +0ms
  eslint:config-array-factory Loading plugin "@typescript-eslint" from /home/alex/tracker/.eslintrc.cjs +1ms
  eslint:config-array-factory Loaded: @typescript-eslint/eslint-plugin@2.30.0 (/home/alex/tracker/node_modules/@typescript-eslint/eslint-plugin/dist/index.js) +1ms
  eslint:config-array-factory Failed to load plugin '@typescript-eslint' declared in '.eslintrc.cjs'. +193ms
TypeError: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.cjs': Cannot convert undefined or null to object
Referenced from: /home/alex/tracker/.eslintrc.cjs
    at Function.getOwnPropertyNames (<anonymous>)
    at /home/alex/tracker/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unbound-method.js:79:19
    at Array.map (<anonymous>)
    at Object.<anonymous> (/home/alex/tracker/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unbound-method.js:77:48)
    at Module._compile (/home/alex/tracker/node_modules/v8-compile-cache/v8-compile-cache.js:194:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:972:32)
    at Function.Module._load (internal/modules/cjs/loader.js:872:14)
    at Module.require (internal/modules/cjs/loader.js:1012:19)
    at require (/home/alex/tracker/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
@bradzacher
Copy link
Member

Could you please ensure you use the issue template for future issues.
We have the templates so that we can collect all of the required information up front, and to help expose documentation.

In this instance, there are many version numbers that are missing that might help here.


I am unable to repro this.
I just installed node v13.13.0, and ran the test suite against the rule that's failing (unbound-method and it's running fine.

Could you please provide a repro repo?

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin labels Apr 27, 2020
@Chenwenfeng87
Copy link

Hi,
Anyone facing this issue, it was ok until yesterday, however i notice that "@typescript-eslint/experimental-utils@2.30.0." this cause issue, is it because of additional . behind 0?
PS xxxxxx\Temp> npx create-react-app matui

Creating a new React app in xxxxxxx\Temp\testing.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

npm ERR! code ETARGET
npm ERR! notarget No matching version found for @typescript-eslint/experimental-utils@2.30.0.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of '@typescript-eslint/eslint-plugin'
npm ERR! notarget

npm ERR! A complete log of this run can be found in:
npm ERR! xxxxxxxx\AppData\Roaming\npm-cache_logs\2020-04-28T09_45_24_302Z-debug.log
has failed.

@bradzacher
Copy link
Member

bradzacher commented Apr 28, 2020

No - that's just how npm outputs its error message, with a full stop at the end of the sentence.

Chances are if your install is failing, it's due to a dodgy cache.
I just tried an npm install locally and it's working fine.

@Ximik
Copy link
Author

Ximik commented Apr 28, 2020

@bradzacher
Hello.

Sorry for the template, I didn't get which to choose and created and issue from scratch. Will be more accurate next time.

Here is the repo
https://github.com/Ximik/typescript-eslint-issues

Fails with node v13.13.0. Works on v12.16.1.
The only difference between them I've found so far is v13.13.0 compiled without ICU flag.

Thank you.

@bradzacher
Copy link
Member

Your repro repo works fine for me.

image

I suspect the problem is that you're not actually running on node 13.
The only way you can get the error you've listed is if you're running the rule on <8.10.0.

@Ximik
Copy link
Author

Ximik commented Apr 28, 2020

It's very strange

alex@laptop ~ $ node -v
v13.13.0
alex@laptop ~ $ npm -v
6.14.4
alex@laptop ~ $ equery u nodejs
[ Legend : U - final flag setting for installation]
[        : I - package is installed with flag     ]
[ Colors : set, unset                             ]
 * Found these USE flags for net-libs/nodejs-13.13.0:
 U I
 + + cpu_flags_x86_sse2 : Use the SSE2 instruction set
 - - debug              : Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
 - - doc                : Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
 - - icu                : Enable ICU (Internationalization Components for Unicode) support, using dev-libs/icu
 - - inspector          : Enable V8 inspector
 + + npm                : Enable NPM package manager
 - - pax_kernel         : Enable building under a PaX enabled kernel
 + + snapshot           : Enable snapshot creation for faster startup
 + + ssl                : Add support for SSL/TLS connections (Secure Socket Layer / Transport Layer Security)
 + + system-ssl         : Use system OpenSSL instead of the bundled one
 - - systemtap          : Enable SystemTAP/DTrace tracing
 - - test               : Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)

And <8.10.0 doesn't work .cjs extension (if I remember correct). Can you say me why it doesn't work with old nodejs, so I can dig it?

@bradzacher
Copy link
Member

bradzacher commented Apr 28, 2020

The rule whitelists built in methods that are known to be pre bound by design.

It does this dynamically by getting the property names of various builtins.

/**
* The following is a list of exceptions to the rule
* Generated via the following script.
* This is statically defined to save making purposely invalid calls every lint run
* ```
SUPPORTED_GLOBALS.flatMap(namespace => {
const object = window[namespace];
return Object.getOwnPropertyNames(object)
.filter(
name =>
!name.startsWith('_') &&
typeof object[name] === 'function',
)
.map(name => {
try {
const x = object[name];
x();
} catch (e) {
if (e.message.includes("called on non-object")) {
return `${namespace}.${name}`;
}
}
});
}).filter(Boolean);
* ```
*/
const nativelyNotBoundMembers = new Set([
'Promise.all',
'Promise.race',
'Promise.resolve',
'Promise.reject',
'Promise.allSettled',
'Object.defineProperties',
'Object.defineProperty',
'Reflect.defineProperty',
'Reflect.deleteProperty',
'Reflect.get',
'Reflect.getOwnPropertyDescriptor',
'Reflect.getPrototypeOf',
'Reflect.has',
'Reflect.isExtensible',
'Reflect.ownKeys',
'Reflect.preventExtensions',
'Reflect.set',
'Reflect.setPrototypeOf',
]);
const SUPPORTED_GLOBALS = [
'Number',
'Object',
'String', // eslint-disable-line @typescript-eslint/internal/prefer-ast-types-enum
'RegExp',
'Symbol',
'Array',
'Proxy',
'Date',
'Infinity',
'Atomics',
'Reflect',
'console',
'Math',
'JSON',
'Intl',
] as const;
const nativelyBoundMembers = SUPPORTED_GLOBALS.map(namespace => {
const object = global[namespace];
return Object.getOwnPropertyNames(object)
.filter(
name =>
!name.startsWith('_') &&
typeof (object as Record<string, unknown>)[name] === 'function',
)
.map(name => `${namespace}.${name}`);
})
.reduce((arr, names) => arr.concat(names), [])
.filter(name => !nativelyNotBoundMembers.has(name));

The list of global names it uses have been chosen to work with node 8.10.0 or higher.

The only way you can get the error you've listed is if one of the global names in the list does not exist, which should not be possible.

@kalkin
Copy link

kalkin commented Apr 30, 2020

Hah, I have exact the same issue also on Gentoo!

⚙> node --version
v13.9.0
⚙> npm --version
6.13.7
⚙> equery u nodejs
[ Legend : U - final flag setting for installation]
[        : I - package is installed with flag     ]
[ Colors : set, unset                             ]
 * Found these USE flags for net-libs/nodejs-13.9.0:
 U I
 + + bundled-ssl        : Use bundled version of OpenSSL (hack)
 + + cpu_flags_x86_sse2 : Use the SSE2 instruction set
 - - debug              : Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see
                          https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
 + + doc                : Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
 - - icu                : Enable ICU (Internationalization Components for Unicode) support, using dev-libs/icu
 - - inspector          : Enable V8 inspector
 + + libressl           : Use dev-libs/libressl instead of dev-libs/openssl when applicable (see also the ssl useflag)
 + + npm                : Enable NPM package manager
 - - pax_kernel         : Enable building under a PaX enabled kernel
 + + snapshot           : Enable snapshot creation for faster startup
 + + ssl                : Add support for SSL/TLS connections (Secure Socket Layer / Transport Layer Security)
 - - systemtap          : Enable SystemTAP/DTrace tracing
 - - test               : Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)

@kalkin
Copy link

kalkin commented Apr 30, 2020

I just tried with the prebuild downloaded LTS node version and it works :(. So it's either the Gentoo version is not compatible or some USE_FLAGS are needed.

@bradzacher
Copy link
Member

bradzacher commented Apr 30, 2020

I don't have a linux box to test this on.
The code for the rule is linked above, it'd be great if someone could run the linked code in a local node repl to figure out what's missing exactly.

@Ximik
Copy link
Author

Ximik commented Apr 30, 2020

@bradzacher From the code snippet you've posted it seems like Intl should be accessible. Which is not the case for me and @kalkin (icu is disabled for both of us, which makes NodeJS to be compiled with --with-intl=none flag).

So, you are right, it's not on your end. Thank you for your help and patience.

For those, who has the same issue.
The nodejs should be compiled with (not none) --with-intl in order to work.

@Ximik Ximik closed this as completed Apr 30, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

4 participants