11

I am facing an error in react vite project.

snippet from package.json

"react": "^18.2.0",
"vite": "^5.0.0",
"vite-plugin-svgr": "^4.2.0",

The error is :

D:\React\ACL\Acl28\node_modules\rollup\dist\native.js:64 throw new Error( ^

Error: Cannot find module @rollup/rollup-win32-x64-msvc. 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. at requireWithFriendlyError (D:\React\ACL\Acl28\node_modules\rollup\dist\native.js:64:9) at Object. (D:\React\ACL\Acl28\node_modules\rollup\dist\native.js:73:48) 2 lines matching cause stack trace ... at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at cjsLoader (node:internal/modules/esm/translators:345:17) at ModuleWrap. (node:internal/modules/esm/translators:294:7) at ModuleJob.run (node:internal/modules/esm/module_job:218:25) at async ModuleLoader.import (node:internal/modules/esm/loader:329:24) { [cause]: Error: The specified module could not be found. \?\D:\React\ACL\Acl28\node_modules@rollup\rollup-win32-x64-msvc\rollup.win32-x64-msvc.node at Module._extensions..node (node:internal/modules/cjs/loader:1473:18) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at Module.require (node:internal/modules/cjs/loader:1235:19) at require (node:internal/modules/helpers:176:18) at requireWithFriendlyError (D:\React\ACL\Acl28\node_modules\rollup\dist\native.js:62:10) at Object. (D:\React\ACL\Acl28\node_modules\rollup\dist\native.js:73:48) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) { code: 'ERR_DLOPEN_FAILED' } }

Node.js v20.10.0

======== vite.config.js

import { defineConfig } from "vite";
import reactRefresh from '@vitejs/plugin-react';
import svgrPlugin from 'vite-plugin-svgr';

export default defineConfig({

 build: {
     outDir: 'build',
 },
 plugins: [
     reactRefresh(),
     svgrPlugin({
         svgrOptions: {
             icon: true,
         },
     }),
 ],

})

Please help in resolving the problem

The project is working fine in another system which has windows 11 as I my system has. Even if I copied whole working project including node-modules folder from another system into my system , the problem persists. The node version is 20 in my system. Another system has node version 16.16

I am expecting to run my react-vite project properly.

0

13 Answers 13

26

Because you lack of @rollup/rollup-linux-x64-gnu dependency

In package.json you add this dependency as a optinal. And then you run it at windown so ok, run it at linux still ok

"optionalDependencies": {
    "@rollup/rollup-linux-x64-gnu": "4.6.1"
  }
Sign up to request clarification or add additional context in comments.

1 Comment

I had the same issue with Cloudflare Pages deployment and this answer helped me resolve it
4

Add to your dependencies in your package.json: "@rollup/rollup-linux-x64-gnu": "^4.9.2"

That's all you need

1 Comment

This can't be installed on unix or windows env. Modifying package.json seems the best option I have added an answer about it.
4

There are couple of good answers on this github thread on the vite github repository it offered two alternative on the package.json:

  "resolutions": {
    "rollup": "npm:@rollup/wasm-node"
  },

alternative:

"overrides": {
  "vite": {
    "rollup": "npm:@rollup/wasm-node"
  }
}

1 Comment

"resolutions" worked perfectly
3

This might be happening because you are mounting your volumes wrong. If your docker compose file has this in it:

services:
  app:
    volumes:
      - .:/app

You are copying all your local node_modules into the container even though there might be conflicts with different operating systems between your host and the container image. Even if you had node_modules in your dockerignore file it would still copy the wrong node modules.

To mitigate this change your volumes to not be on the root level, eg:

services:
  app:
    volumes:
      - .:/app/src 

Comments

2

I'm facing the same problem since yesterday... I solved it by downloading the most recent Visual C++ Redistributable. I saw a lot of guys in another forum that also got it.

You can download it here:

https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170

Comments

1

You can try these to solve this issue. These steps worked for me :

  1. Install Microsoft C++ Redistributable 2015.

  2. Remove package-lock.json.

  3. Delete node_modules folder.

  4. Restart the machine.

  5. Run npm install.

  6. Run npm run dev if you're using vite.

1 Comment

Step 2, 3, 5 and 6 is what worked for me. Thanks!
1

The only that worked for me was cleaning node_modules, deleting package-lock.json and npm install. After that package-lock was rebuilt and error was gone

Comments

0

Apparently this happens because Rollup uses the Visual Studio Redistributable to make native calls (source). If you don't have a Visual Studio redistributable installed, install one from https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist for your platform. After doing that, try to run package installation or whatever npm command you were trying to run again (you may need to do some extra steps to refresh things).

Rollup itself has recently made a change to add a more friendly error message about this. See Add friendly error for missing MSVC redistributable #5284.

Comments

0

this actually happended to me try to uninstall node v20.10.0 you have now and download node version v18.12.0

1 Comment

The question mentions that they have already tried node v20 and v16. Why do you think it would be useful for them to try v18 ? Also it might have only been a fix for you because you are using different versions of npm packages.
0

I had the same error. It was fixed by updating node.js; try running:

nvm install latest

Use the command below to make sure that you are running the desired version of node

nvm use vA.B.C

vA.B.C = the version number that you'd like to use.

Once the new version of node is installed, delete the node_modules package and the package-lock.json

Run the npm install command and try running the app.

Comments

0

Experienced this error in a React + Vite 5 app deployed via Netlify using npm not yarn. Fixed it by installing dependencies in CI mode before the build phase.

# netlify.toml
[build]
  publish = "dist"
  command = "npm ci && npm run build"

Comments

0

for linux: cd into folder with project and execute

npm install

npm install @rollup/rollup-linux-x64-gnu
npx vite .

Comments

0

I got this error:

Error: Cannot find module @rollup/rollup-linux-x64-gnu. npm has a bug related to optional dependencies

And this one worked for me:

rm -rf node_modules package-lock.json

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.