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

Failed to load plugin '@nrwl/nx' declared in 'apps/project/.eslintrc.json » ../../../.eslintrc.js#overrides[1]': Cannot find module '@swc/core-linux-x64-gnu' #8969

Closed
jogelin opened this issue Feb 14, 2022 · 30 comments
Assignees
Labels
blocked: retry with latest Retry with latest release or head. outdated scope: linter Issues related to Eslint support in Nx type: bug

Comments

@jogelin
Copy link
Contributor

jogelin commented Feb 14, 2022

Current Behavior

Since the upgrade the Nrwl 13+, when I run the affected lint target on the CI (azure devops), I got this error on all projects:

Failed to load plugin '@nrwl/nx' declared in 'apps/shared-ui-e2e/.eslintrc.json » ../../../.eslintrc.js#overrides[1]': Cannot find module '@swc/core-linux-x64-gnu'
Require stack:
- /var/vsts/temporary-agent-grizzly-l4j54/1/s/node_modules/@swc/core/binding.js
- /var/vsts/temporary-agent-grizzly-l4j54/1/s/node_modules/@swc/core/index.js
- /var/vsts/temporary-agent-grizzly-l4j54/1/s/node_modules/@swc-node/core/lib/index.js
- /var/vsts/temporary-agent-grizzly-l4j54/1/s/node_modules/@swc-node/register/lib/register.js
- /var/vsts/temporary-agent-grizzly-l4j54/1/s/node_modules/@nrwl/eslint-plugin-nx/src/resolve-workspace-rules.js
- /var/vsts/temporary-agent-grizzly-l4j54/1/s/node_modules/@nrwl/eslint-plugin-nx/src/index.js
- /var/vsts/temporary-agent-grizzly-l4j54/1/s/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
Referenced from: /var/vsts/temporary-agent-grizzly-l4j54/1/s/.eslintrc.js

I already put a comment on this closed issue: #8735.
@meeroslav also made a PR #8831 that should fix the issue on 13.7.3 but I am still having it.

For the moment I have to install the library each time I run a lint command on the CI:

 yarn add @swc/core-linux-x64-gnu --dev

But this is increasing a lot of the time to the CI process

Expected Behavior

To not have this error

Steps to Reproduce

yarn affected:lint

Environment

   Node : 16.13.1
   OS   : darwin x64
   yarn : 1.22.17

   nx : 13.8.1
   @nrwl/angular : 13.8.1
   @nrwl/cli : 13.8.1
   @nrwl/cypress : 13.8.1
   @nrwl/detox : undefined
   @nrwl/devkit : 13.8.1
   @nrwl/eslint-plugin-nx : 13.8.1
   @nrwl/express : undefined
   @nrwl/jest : 13.8.1
   @nrwl/js : 13.8.1
   @nrwl/linter : 13.8.1
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : 13.8.1
   @nrwl/nx-cloud : undefined
   @nrwl/react : undefined
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.8.1
   @nrwl/tao : 13.8.1
   @nrwl/web : 13.8.1
   @nrwl/workspace : 13.8.1
   typescript : 4.5.5
   rxjs : 7.5.4
   ---------------------------------------
   Community plugins:
   	 @angular/animations: 13.2.2
   	 @angular/cdk: 13.2.2
   	 @angular/common: 13.2.2
   	 @angular/compiler: 13.2.2
   	 @angular/core: 13.2.2
   	 @angular/forms: 13.2.2
   	 @angular/material: 13.2.2
   	 @angular/platform-browser: 13.2.2
   	 @angular/platform-browser-dynamic: 13.2.2
   	 @angular/router: 13.2.2
   	 @auth0/auth0-angular: 1.7.0
   	 @ngneat/edit-in-place: 1.6.1
   	 @ngneat/transloco: 3.1.3
   	 @ngrx/component: 13.0.2
   	 @ngrx/component-store: 13.0.2
   	 ng2-charts: 3.0.8
   	 single-spa-angular: 6.0.1
   	 @angular-builders/custom-webpack: 13.1.0
   	 @angular-devkit/architect: 0.1302.3
   	 @angular-devkit/build-angular: 13.2.3
   	 @angular/cli: 13.2.3
   	 @angular/compiler-cli: 13.2.2
   	 @angular/language-service: 13.2.2
   	 @compodoc/compodoc: 1.1.18
   	 @ngneat/spectator: 10.0.0
   	 @storybook/angular: 6.4.19
   	 @twittwer/compodoc: 1.6.6
@FrozenPandaz FrozenPandaz added the scope: linter Issues related to Eslint support in Nx label Feb 14, 2022
@JosefBredereck
Copy link
Contributor

JosefBredereck commented Feb 15, 2022

Same goes for Win10 with @swc/core-win32-x64-msvc

Error: Failed to load plugin '@nrwl/nx' declared in '.eslintrc.json#overrides[1]': Cannot find module '@swc/core-win32-x64-msvc'

What I was able to discover until now is that the machine was not able to unlink a file during the installation process and caused the required files not to have been added.

Error: EPERM: operation not permitted, unlink [...]\node_modules\@swc\.core-win32-x64-msvc.DELETE\swc.win32-x64-msvc.node

@meeroslav
Copy link
Contributor

Hi @jogelin, thank you for reporting the issue.

You should definitely not install @swc/core-linux-x64-gnu on CI during your pipeline. It should already be set in your lock file as an optional dependency. Can you please check for it in the package-lock.json or yarn.lock? If not there, you might need to delete the node_modules and your lock file and run install (npm install or yarn) to regenerate them again.
All the @swc/core-linux-* should be added as an optional dependency, so your CI machine would pick them up on the install phase. Please have in mind that if you cache node_modules on CI, you would have to invalidate the CI cache as well.

Let me know if this helped.

@meeroslav
Copy link
Contributor

@JosefBredereck Thank you for reporting. I will have a look at the windows issue soon.

In the meantime can you check this thread, since the issue lies within @swc-project swc-project/swc#1351

@meeroslav meeroslav self-assigned this Feb 15, 2022
@meeroslav meeroslav added the blocked: retry with latest Retry with latest release or head. label Feb 15, 2022
@jogelin
Copy link
Contributor Author

jogelin commented Feb 15, 2022

@meeroslav this is ok now. You were right, just the yarn.lock that kept the dependencies in non optional :(

@jogelin jogelin closed this as completed Feb 15, 2022
@meeroslav
Copy link
Contributor

Good to hear that! Thank you for swift response

@bubblegumsoldier
Copy link

Hi, I am having the same issue, but not with yarn but with npm. I have checked the package-lock.json where I find the "@swc/core-linux-x64-gnu" as an "optionalDependency" in "node_modules/@swc/core" and "node_modules/@nrwl/eslint-plugin-nx" and and as "requires" in "@nrwl/eslint-plugin-nx" and "@swc/core". I am using the npm ci command which takes care of not caching the node_modules folder. Thus neither one could really be the problem. Any ideas or recommendations?

@kasparsuvi1
Copy link

Hi, I am having kind of the same issue. Updated nx to latest and deleted node_modules/package-lock.
Linting in project is working, but VSCode Eslint output channel is showing me same errors:
UnhandledPromiseRejectionWarning: Error: Failed to load plugin '@nrwl/nx' declared in '.eslintrc.json': Cannot find module '@swc/core-win32-x64-msvc'
Using Windows and npm

And I assume this is the problem why vscode cant underline eslint errors. Tho when running nx affected:lint --all all the errors and warning are provided.

@meeroslav
Copy link
Contributor

meeroslav commented Feb 18, 2022

@JosefBredereck I have just checked the windows and everything works as expected. If you have an issue, please follow the following steps:

  • Remove lock file & node_modules (e.g. rm -rf node_modules package-lock.json yarn.lock pnpm-lock.yaml)
  • Clear the cache (npm cache clean or yarn cache clean)
  • Re-install dependencies (e.g. npm i or yarn or pnpm)

That should ensure your lock file has properly picked up missing @swc/core-... packages.

The same solution applies also to @bubblegumsoldier.

@meeroslav
Copy link
Contributor

meeroslav commented Feb 18, 2022

@kasparsuvi1, the workspace rules are separated from the standard linter.

Can you tell me on which file you see these errors? Did you try restarting the ESLint server in VSCode?

Screenshot 2022-02-18 at 11 37 33

Check if you have following folder: node_modules\@swc\core-wind32-x64-msvc. If not check if it exists in the package-lock. You might need to reset your npm cache and restart the whole process (deleting files, running the install again, restarting ESLint Server) if it's missing.

npm cache clean --force

@kasparsuvi1
Copy link

@meeroslav , thanks for recommendations.

I dont get node_modules\@swc\core-wind32-x64-msvc installed not even after cache clean and new install. Only node_modules\@swc\core-wind32-ia32-msvc is installed.
Under package-lock there is core-wind32-x64-msvc, but as optional. I think i have wrong architecture of windows for that? When i try to change it to required dependencie i get error:
Unsupported platform for @swc/core-win32-x64-msvc@1.2.140: wanted {"os":"win32","arch":"x64"} (current: {"os":"win32","arch":"ia32"})

Should i change my os architecture?

@meeroslav
Copy link
Contributor

It should be marked as optional. That is intentional. What that means is that if the underlying architecture doesn't support it, it will not break the npm install.

Based on your error, it seems that you have the correct one installed already ({"os":"win32","arch":"ia32"} and @swc\core-wind32-ia32-msvc installed). If linter is looking for @swc/core-win32-x64-msvc, that might be an error in the @swc-node/register implementation.

Perhaps @Brooooooklyn has some insights?

@Brooooooklyn
Copy link
Contributor

One possible scenario is that the 32-bit version of Node.js is installed and the 64-bit version of VSCode is installed. That is why @swc\core-wind32-ia32-msvc installed but eslint vscode plugin want to load @swc\core-wind32-x64-msvc

@meeroslav
Copy link
Contributor

Thank you @Brooooooklyn, I didn't consider that angle.

@kasparsuvi1 are you running lint from the terminal or using the plugin from the IDE?

@kasparsuvi1
Copy link

kasparsuvi1 commented Mar 4, 2022

From the terminal linting works, plugin from the IDE does not. Maybe I have messed up versions of node/vscode, trying to fix reinstalling those in 64-bit versions. Thanks for the help!

Edit: And it fixed the problem, thank you again! Never spring to my mind that it would be connected and that I had 32-bit node installed...

@zoechi
Copy link

zoechi commented Mar 10, 2022

@meeroslav but it's now not optional anymore https://github.com/nrwl/nx/pull/9142/files or did I misinterpret something

@meeroslav
Copy link
Contributor

@zoechi if you look at "@swc/core" dependencies in the lock file you will notice that it has all those dependencies, marked as optional: https://github.com/nrwl/nx/blob/master/yarn.lock#L5663-L5680

@swc-node/register depends on @swc-node/core which depends on @swc/core.
I explicitly added optional dependencies the first time while trying to solve this issue, due to misleading information on related issues, but the problem turned out to be in the stale node_modules/lock combo.

@ubergeoff
Copy link

ubergeoff commented Mar 16, 2022

Had this same issue in my CI pipeline...

Used to have:

npm ci --no-optional

Changed to:

npm ci

Working again...

@meeroslav
Copy link
Contributor

Yeah no-optional will definitely break it

@shaharkazaz
Copy link
Contributor

shaharkazaz commented Mar 23, 2022

@meeroslav I've tried all of the above but I'm still having the issue.
Here is the CI run that fails, locally everything seems to work as expected.
I've searched my package-lock.json and found the optional dependencies.
Any idea?

@meeroslav
Copy link
Contributor

Hey, @shaharkazaz I'm sorry for your trouble.
The issue is here: https://github.com/ngneat/transloco/blob/master/package-lock.json#L23459-L23482
You can see that although all the @swc/core-... packages are marked as optional in @swc/core your lock file only added explicitly the one for macOS. Looking at the lock file there seems to be some other information missing such as integrity hashes and direct paths to resolved versions. Not sure how your lock file was generated, but it's obviously malformed.

I created a PR that solve it: jsverse/transloco#552

@meeroslav
Copy link
Contributor

You should also update the node version to v16 on your CI runs, since this is the LTE now.

@shaharkazaz
Copy link
Contributor

@meeroslav I appreciate the PR!
I re-created the lock locally on my computer, nothing special (I'm using macOS).
npm version: 8.4.0
node version: 14.8.2

@meeroslav
Copy link
Contributor

meeroslav commented Mar 24, 2022

Perhaps you should consider updating to node v16. Not sure if that's the issue. Either way, the lint passed with the new lock file.

Btw, your CI was running npm i instead of npm ci so it was overriding the lock file every time.

@StephenStrickland
Copy link

I'm also randomly seeing this issue in my CI environment (ADO, ubuntu-latest), it seems to fix itself after doing several iterations of: clearing nx cache, deleting node_modules, deleting package-lock.json, npm i to rebuild the lockfile. Any suggestions? I didn't start having these issues until I did a recent nx migration from 13.2.0 to latest 13.9.6. Is this is some kind of regression between 13.2 to 13.9? I've seen several other tickets logged with similar behavior over the last several months.

@meeroslav
Copy link
Contributor

@StephenStrickland we recently switched from using ts-node to swc/node for the transpilation of linter rules. This made reaching large performance increases for workspace-lint possible.

Unfortunately, the downside is that npm depending on the node version can mess up the packages with automated updates and most likely requires a clean reinstall to untangle itself. With yarn and pnpm we didn't notice those issues.

@StephenStrickland
Copy link

@meeroslav thanks for the reply, implemented pnpm on a few other projects, this will probably lead me to do the same to reduce/eliminate this issue.

@marcintokarski
Copy link

This is probably problem related to npm and package-lock.json. I had the same problem on CI (docker), when package-lock.json was generated on windows by npm@8.3.1. I upgraded npm to 8.5.1 and regenerate package-lock.json (still on windows), and everything start works locally and on CI :)

@wobo-nate
Copy link

wobo-nate commented Aug 10, 2022

When this happened to me with github actions failing to install the optionalDependencies, I was able to fix it by ensuring that my project had a direct devDependency on nx. It was insufficient to have a devDependency on @nrwl/cli. 🤷

"devDependencies": {
  "@nrwl/cli": "13.9.5",
  "nx": "13.9.5",         // need both!
  // ...
}

This is surprising to me because the official nx example repo does not have this direct dependency. Edit: yes it does in v14, thanks for the correction @meeroslav

Edit 2: problem resurfaced after rebuilding package-lock today despite having both deps. Still looking for a permanent fix.

@meeroslav
Copy link
Contributor

@nrwl/cli is replaced by nx, so you don't actually need them both. You just need the Nx. And Nx-examples repo actually has it as a dependency: https://github.com/nrwl/nx-examples/blob/ff6a4856d3d5337205362d264b681fe849dbf7a0/package.json#L101

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: retry with latest Retry with latest release or head. outdated scope: linter Issues related to Eslint support in Nx type: bug
Projects
None yet
Development

No branches or pull requests