You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel执行npm install && npm run dev报错,需安装适配的Node.js

解决Laravel项目npm install && npm run dev的版本适配报错

问题描述

在Laravel项目中执行npm install && npm run dev时触发报错,核心错误信息如下:

WARN engine sass@1.57.1: wanted: {"node":">=12.0.0"} (current: {"node":"8.10.0"})
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
npm WARN deprecated axios@0.19.2: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
WARN engine vue-trumbowyg@3.6.2: wanted: {"node":">= 6.9.0","npm":">= 3.10.8"}
WARN engine @coreui/coreui@2.1.16: wanted: {"node":">= 8.7","npm":">= 5"}
npm ERR! Linux 4.15.0-197-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! code EMISSINGARG

npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror     at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror     at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror     at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror     at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror     at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror     at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror     at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror     at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror     <http://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/market2/growex2/npm-debug.log

报错根源是当前Node.js(v8.10.0)和npm(v3.5.2)版本过低,无法满足项目依赖包的版本要求,同时旧版npm存在自身bug导致EMISSINGARG错误。

解决步骤

1. 卸载旧版本Node.js和npm

针对Ubuntu/Debian系统,执行以下命令清理旧版本:

sudo apt remove nodejs npm -y
sudo apt autoremove -y
sudo rm -rf /usr/local/lib/node_modules /usr/local/bin/npm /usr/local/bin/node

2. 安装Node版本管理器(nvm)

nvm可快速切换Node.js版本,避免版本冲突:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

执行后重启终端,或运行以下命令让nvm生效(bash用.bashrc,zsh用.zshrc):

source ~/.bashrc

3. 安装适配的Node.js版本

根据依赖最低要求,选择>=12.0.0的LTS版本(推荐16.x或18.x,稳定性更强):

# 安装Node.js 16.x LTS版本
nvm install 16
# 设置为默认版本
nvm alias default 16

若项目根目录存在.nvmrc文件,直接执行nvm install即可自动安装指定版本。

4. 验证版本

确认Node.js和npm版本符合要求:

node -v # 输出应为v16.x.x或更高
npm -v # 对应npm版本应为8.x或更高

5. 重新执行npm命令

回到Laravel项目根目录,清理旧依赖缓存后重新安装:

rm -rf node_modules package-lock.json
npm install && npm run dev

内容的提问来源于stack exchange,提问作者Artem D

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 13:50:41