language-tools: Cannot find module '@rollup/rollup-darwin-arm64'
Describe the bug
VS Code crashes with:
Error: Cannot find module ‘@rollup/rollup-darwin-arm64’
Reproduction
New Apple M3 MacBook Pro laptop using base SvelteKit with Typescript scaffolding.
Partial output:
Initialize language server at file:///Users/xxx/Documents/Programs/svelteTSTest Initialize new ts service at /Users/xxx/Documents/Programs/svelteTSTest/tsconfig.json Trying to load configs for /Users/xxx/Documents/Programs/svelteTSTest Error while loading config at /Users/xxx/Documents/Programs/svelteTSTest/svelte.config.js Error: Cannot find module @rollup/rollup-darwin-arm64. 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 (/Users/xxx/Documents/Programs/svelteTSTest/node_modules/.pnpm/rollup@4.9.6/node_modules/rollup/dist/native.js:87:9) at Object.<anonymous> (/Users/xxx/Documents/Programs/svelteTSTest/node_modules/.pnpm/rollup@4.9.6/node_modules/rollup/dist/native.js:96:48) ... 2 lines matching cause stack trace ... at Module.load (node:internal/modules/cjs/loader:1173:32) at node:internal/modules/cjs/loader:1014:12 at Function._load (node:electron/js2c/asar_bundle:2:13327) at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29) at ModuleJob.run (node:internal/modules/esm/module_job:194:25) { [cause]: Error: Cannot find module '@rollup/rollup-darwin-arm64' Require stack: - /Users/xxx/Documents/Programs/svelteTSTest/node_modules/.pnpm/rollup@4.9.6/node_modules/rollup/dist/native.js at Function._resolveFilename (node:internal/modules/cjs/loader:1131:15) at node:internal/modules/cjs/loader:976:27 at Function._load (node:electron/js2c/asar_bundle:2:13327) at Module.require (node:internal/modules/cjs/loader:1197:19) at require (node:internal/modules/cjs/helpers:121:18) at requireWithFriendlyError (/Users/xxx/Documents/Programs/svelteTSTest/node_modules/.pnpm/rollup@4.9.6/node_modules/rollup/dist/native.js:69:10) at Object.<anonymous> (/Users/xxx/Documents/Programs/svelteTSTest/node_modules/.pnpm/rollup@4.9.6/node_modules/rollup/dist/native.js:96:48) at Module._compile (node:internal/modules/cjs/loader:1318:14) at Object..js (node:internal/modules/cjs/loader:1373:10) at Module.load (node:internal/modules/cjs/loader:1173:32) { code: 'MODULE_NOT_FOUND', requireStack: [ '/Users/xxx/Documents/Programs/svelteTSTest/node_modules/.pnpm/rollup@4.9.6/node_modules/rollup/dist/native.js' ] }Expected behaviour
Not crash on VS Code launch or when Language Server is restarted.
System Info
VS Code version: Code 1.86.0 (05047486b6df5eb8d44b2ecd70ea3bdf775fd937, 2024-01-31T10:29:11.933Z) OS version: Darwin arm64 23.3.0
Which package is the issue about?
Svelte for VS Code extension
Additional Information, eg. Screenshots
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 15 (5 by maintainers)
Have you tried this?
This is most definitely not a bug on our side. The error is caused by the dependencies that you imported in the svelte.config.js. It sounds like you either copied your node_module from another machine. Or something is running Rosetta during the installation, Maybe terminal shell or node.js installation. Can you try reinstalling the module? If just running `npm i’ doesn’t help, try what the error suggests. And if both don’t work. Try installing it in the default terminal and check if your node.js installation is rosetta-based.
worked by doing
sudo npm iandsudo npm run devafter deleting node_modules and package-lock.jsonEdit: in most cases running npm with root is considered bad. first try deleting the
node_modulesdirectory and runningnpm iagain.for any future readers, please don’t do this without educating yourself first if it is a good idea to run npm with root (spoiler: its not)
My issue was that my
nodeandnpminstances had an architecture mismatch. I had installednodethroughnvmrunning on a terminal not using rosetta. Uninstalling and reinstalling node (this time on a terminal with rosetta) resolved it.https://stackoverflow.com/a/67907214
Check your node arch and that it matches your chipset, i.e.
node -p "process.arch"Also if installed via brew, check brew arch too withbrew configso it says arm64 And check which brew is running:file $(which brew)Maybe you’ll need to uninstall the versions if they are not for the arch. Then after this, I suggest the rm -rf node_modules, cache clean and npm rebuild for your current arch!I had same issue, I resolved by removing my node modules, package-lock.json file and reinstalled node modules.
Closing as resolved in a discord chat.
https://discord.com/channels/457912077277855764/1204094017206354102
@ermincelikovic, please read through the previous comments. This is likely because the tool you used to install node.js is running Rosetta, the translation layer for running x64 software on Apple silicon.
Check if whatever tool you used to install node.js is running in x64. If you used the installer, try downloading the Apple Arm version. If you don’t know how, try reading through the thread linked above. Or search for
esbuild/darwin-arm64there might be some similar issues you can find resources to debug.Delete your node_modules folder and run “npm i” again
I had the exact same issue, and reading through comments, I realized that my docker.compose file had a volume share between my mac and the linux docker container, therefore pushing the linux node_modules into the host, which caused these problems.
svelte.config.jsprovides the preprocess config so that the language server can preprocess your code and feed it into the svelte compiler as bundlers like vite do. The error message says that a required package is missing. The missing package is a “native” package that requires a different build based on your OS and architecture. The different build is usually part of the reason why it is performant. If you copynode_modulesfrom another machine, you might be copying things meant for a different OS and architecture, thus missing some required dependencies. Furthermore, the error message also suggests some bug/undesirable in npm might cause these “optional” dependencies not to be installed.I am not suggesting you check what package might be the cause, but try reinstalling things and see if it can correctly detect that you’re using arm64 Mac this time. And npm would install the required package.