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

Error: Failed to load plugin '@typescript-eslint' declared in '--config » plugin:@wordpress/recommended': Cannot find module 'typescript' #29940

Closed
ocean90 opened this issue Mar 17, 2021 · 4 comments · Fixed by #29942
Assignees
Labels
[Package] ESLint plugin /packages/eslint-plugin [Package] Scripts /packages/scripts [Type] Bug An existing feature does not function as intended

Comments

@ocean90
Copy link
Member

ocean90 commented Mar 17, 2021

Description

Using @wordpress/scripts@14.0.0 and wp-scripts lint-js is currently failing to lint JavaScript files because typescript is missing as a dependency.

Step-by-step reproduction instructions

  1. Create package.json
{
  "name": "ts",
  "version": "0.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "private",
  "devDependencies": {
    "@wordpress/scripts": "^14.0.0"
  }
}
  1. Create index.js
  2. Run npx wp-scripts lint-js index.js

Expected behaviour

File is linted without errors.

Actual behaviour

npx wp-scripts lint-js index.js

Oops! Something went wrong! :(

ESLint: 7.22.0

Error: Failed to load plugin '@typescript-eslint' declared in '--config » plugin:@wordpress/recommended': Cannot find module 'typescript'
Require stack:
- /private/tmp/ts/node_modules/tsutils/typeguard/2.8/node.js
- /private/tmp/ts/node_modules/tsutils/typeguard/2.9/node.js
- /private/tmp/ts/node_modules/tsutils/typeguard/3.0/node.js
- /private/tmp/ts/node_modules/tsutils/typeguard/3.2/node.js
- /private/tmp/ts/node_modules/tsutils/typeguard/node.js
- /private/tmp/ts/node_modules/tsutils/typeguard/index.js
- /private/tmp/ts/node_modules/tsutils/index.js
- /private/tmp/ts/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js
- /private/tmp/ts/node_modules/@typescript-eslint/eslint-plugin/dist/util/index.js
- /private/tmp/ts/node_modules/@typescript-eslint/eslint-plugin/dist/rules/adjacent-overload-signatures.js
- /private/tmp/ts/node_modules/@typescript-eslint/eslint-plugin/dist/rules/index.js
- /private/tmp/ts/node_modules/@typescript-eslint/eslint-plugin/dist/index.js
- /private/tmp/ts/node_modules/@eslint/eslintrc/lib/config-array-factory.js
- /private/tmp/ts/node_modules/@eslint/eslintrc/lib/index.js
- /private/tmp/ts/node_modules/eslint/lib/cli-engine/cli-engine.js
- /private/tmp/ts/node_modules/eslint/lib/eslint/eslint.js
- /private/tmp/ts/node_modules/eslint/lib/eslint/index.js
- /private/tmp/ts/node_modules/eslint/lib/cli.js
- /private/tmp/ts/node_modules/eslint/bin/eslint.js
Referenced from: /private/tmp/ts/node_modules/@wordpress/eslint-plugin/index.js
    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 (/private/tmp/ts/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/private/tmp/ts/node_modules/tsutils/typeguard/2.8/node.js:7:12)
    at Module._compile (/private/tmp/ts/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'm using node v14.15.4 with npm 6.14.11.

Probably introduced by #27143.

@ocean90 ocean90 added [Type] Bug An existing feature does not function as intended [Package] Scripts /packages/scripts [Package] ESLint plugin /packages/eslint-plugin labels Mar 17, 2021
@gziolo
Copy link
Member

gziolo commented Mar 17, 2021

@sirreal or @sarayourfriend, can you investigate how can fix it?

@ocean90
Copy link
Member Author

ocean90 commented Mar 17, 2021

After running npm i -D typescript wp-scripts lint-js is working again.

I think the Create Block workflow didn't catch because Gutenberg itself has typescript added here.

@sarayourfriend sarayourfriend self-assigned this Mar 17, 2021
@sarayourfriend
Copy link
Contributor

sarayourfriend commented Mar 17, 2021

It looks like this is due to an unresolved peer dependency on TypeScript by @typescript-eslint/eslint-plugin. I think there is also an inaccuracy in their package.json that says that the TS dependency is optional: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/package.json#L70

In any case I think we just need to add TypeScript as a dependency of @wordpress/eslint-plugin to fix this, but I'm not sure how to test it. Test instructions in the PR

@gziolo
Copy link
Member

gziolo commented Mar 19, 2021

Hotfix published to npm:

Successfully published:
 - @wordpress/e2e-tests@2.1.1
 - @wordpress/eslint-plugin@9.0.1
 - @wordpress/scripts@14.0.1
lerna success published 3 packages

I was able to finish without errors:

npx @wordpress/create-block

TypeScript wasn't installed when using npm v6. JS linter works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] ESLint plugin /packages/eslint-plugin [Package] Scripts /packages/scripts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants