Ubuntu下npm运行报错Error: Cannot find module ‘node:path‘

执行了apt install npm安装了npm,然后又执行 npm install -g npm更新了一下,执行

     npm run serve

出现奇怪现象,在安装npm的终端里执行这个命令就可以运行,再打开一个新的终端在同样的环境下执行这个命令就是报错,执行简单的npm -v命令也得到的结果都一样,都是报这个错误:

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'node:path'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/cli.js:10:18)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

网上说这种错误是npm的版本和node的版本对不上造成的,但是没注意我安装了哪些npm都安装到哪里了,开始没想到费劲折腾了些时间没搞定,后来无意查看两个终端下npm的真实位置,发现可以正常运行的是/usr/bin/npm,实际是通过链接指向/usr/share/npm/bin/npm-cli.js,运行报错的是/usr/local/bin/npm 指向 /usr/local/lib/node_modules/npm/bin/npm-cli.js,查看后者node_modules/npm/package.json里的版本号是11.1.0,而/usr/bin/npm -v得到的是6.14.0,

node -v获得的node版本是v10.19.0,使用6.14.0的npm是适配的,使用11.1.0版npm显然是高了,问题很清楚了,解决办法是把/usr/local/bin/npm链接删掉,重新创建链接指向/usr/bin/npm,然后在新打开的终端里运行 npm run serve就可以了 。

Error: Cannot find native binding. 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 file:///home/zpl/my-editor/node_modules/rolldown/dist/shared/parse-ast-index-D2PcAmXE.mjs:10703:35 at ModuleJob.run (node:internal/modules/esm/module_job:193:25) ... 2 lines matching cause stack trace ... at async CAC.<anonymous> (file:///home/zpl/my-editor/node_modules/vite/dist/node/cli.js:571:27) { [cause]: Error: Cannot find module '@rolldown/binding-linux-x64-gnu' Require stack: - /home/zpl/my-editor/node_modules/rolldown/dist/shared/parse-ast-index-D2PcAmXE.mjs at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15) ... 2 lines matching cause stack trace ... at require (node:internal/modules/cjs/helpers:119:18) at requireNative (file:///home/zpl/my-editor/node_modules/rolldown/dist/shared/parse-ast-index-D2PcAmXE.mjs:10474:20) at file:///home/zpl/my-editor/node_modules/rolldown/dist/shared/parse-ast-index-D2PcAmXE.mjs:10672:17 at ModuleJob.run (node:internal/modules/esm/module_job:193:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:530:24) at async CAC.<anonymous> (file:///home/zpl/my-editor/node_modules/vite/dist/node/cli.js:571:27) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/zpl/my-editor/node_modules/rolldown/dist/shared/parse-ast-index-D2PcAmXE.mjs' ], cause: Error: Cannot find module '../rolldown-binding.linux-x64-gnu.node' Require stack: - /home/zpl/my-editor/node_modules/rolldown/dist/shared/parse-ast-index-D2PcAmXE.mjs at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15) at Function.Module._load (node:internal/modules/cjs/loader:873:27) at Module.require (node:internal/modules/cjs/loader:1100:19) at require (node:internal/modules/cjs/helpers:119:18) at requireNative (file:///home/zpl/my-editor/node_modules/rolldown/dist/shared/parse-ast-index-D2PcAmXE.mjs:10469:11) at file:///home/zpl/my-editor/node_modules/rolldown/dist/shared/parse-ast-index-D2PcAmXE.mjs:10672:17 at ModuleJob.run (node:internal/modules/esm/module_job:193:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:530:24) at async CAC.<anonymous> (file:///home/zpl/my-editor/node_modules/vite/dist/node/cli.js:571:27) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/zpl/my-editor/node_modules/rolldown/dist/shared/parse-ast-index-D2PcAmXE.mjs' ] } } } npm notice npm notice New major version of npm available! 8.19.4 -> 11.6.2 npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.6.2 npm notice Run npm install -g npm@11.6.2 to update! npm notice npm ERR! code 1 npm ERR! path /home/zpl npm ERR! command failed npm ERR! command sh -c -- create-vite my-editor --template react-ts npm ERR! A complete log of this run can be found in: npm ERR! /home/zpl/.npm/_logs/2025-11-07T06_41_42_413Z-debug-0.log zpl@zpl-Alienware-m15:~$ zpl@zpl-Alienware-m15:~$ zpl@zpl-Alienware-m15:~$ zpl@zpl-Alienware-m15:~$ cd my-editor zpl@zpl-Alienware-m15:~/my-editor$ npm i npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@eslint/config-array@0.21.1', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@eslint/config-helpers@0.4.2', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@eslint/core@0.17.0', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@eslint/eslintrc@3.3.1', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'globals@14.0.0', npm WARN EBADENGINE required: { node: '>=18' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@eslint/js@9.39.1', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@eslint/object-schema@2.1.7', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@eslint/plugin-kit@0.4.1', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@humanfs/core@0.19.1', npm WARN EBADENGINE required: { node: '>=18.18.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@humanfs/node@0.16.7', npm WARN EBADENGINE required: { node: '>=18.18.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@humanwhocodes/retry@0.4.3', npm WARN EBADENGINE required: { node: '>=18.18' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@oxc-project/runtime@0.92.0', npm WARN EBADENGINE required: { node: '^20.19.0 || >=22.12.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/eslint-plugin@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/parser@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/project-service@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/scope-manager@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/tsconfig-utils@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/type-utils@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/types@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/typescript-estree@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/utils@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@typescript-eslint/visitor-keys@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@vitejs/plugin-react@5.1.0', npm WARN EBADENGINE required: { node: '^20.19.0 || >=22.12.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'eslint@9.39.1', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'eslint-scope@8.4.0', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'eslint-visitor-keys@4.2.1', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'espree@10.4.0', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'globals@16.5.0', npm WARN EBADENGINE required: { node: '>=18' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'rolldown@1.0.0-beta.41', npm WARN EBADENGINE required: { node: '^20.19.0 || >=22.12.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'ts-api-utils@2.1.0', npm WARN EBADENGINE required: { node: '>=18.12' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'typescript-eslint@8.46.3', npm WARN EBADENGINE required: { node: '^18.18.0 || ^20.9.0 || >=21.1.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: 'rolldown-vite@7.1.14', npm WARN EBADENGINE required: { node: '^20.19.0 || >=22.12.0' }, npm WARN EBADENGINE current: { node: 'v16.20.2', npm: '8.19.4' } npm WARN EBADENGINE } up to date, audited 196 packages in 4s 51 packages are looking for funding run `npm fund` for details found 0 vulnerabilities zpl@zpl-Alienware-m15:~/my-editor$
11-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arnold-FY-Chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值