I'm facing the following error when the pipeline in my GitHub actions is running:
An unhandled exception occurred: Cannot find module @rollup/rollup-linux-x64-gnu. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try
npm i
again after removing both package-lock.json and node_modules directory.
This error is shown up when I run the test or even the build:
And here is my .yml:
And there are my scripts:
am I doing something wrong?
I have tried with other node versions and caching npm
.
Optional dependencies failing to install on a different host OS is now fixed by npm/cli#8184 as part of npm 11.3.0
. You no longer need to specify the *
wildcard manually.
If your project supports it you can update to node 24.0.2
, the earliest version that ships with the fix, otherwise just update npm
to 11.3.0
individually.
After updating, make sure to delete your package-lock.json
file and node_modules
folder, then run npm install
again for a clean installation with the fix applied.
When using GitHub Actions or other deployment platforms, ensure they are also updated to use a version that includes the fix.
If updating node
or npm
in your project isn't feasible, see the original answer below.
This is a common issue, see this thread if you want the full explanation and all possible solutions.
Adding this to the package.json
and running npm install
again will usually fix it in most cases:
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "*"
}