npm run dev无法在vite laravel 9中正常工作

24
users-iMac-2:backend NEHAL$ npm run dev

> dev
> vite

file:///Users/user/Desktop/backend/node_modules/vite/bin/vite.js:7
    await import('source-map-support').then((r) => r.default.install())
    ^^^^^

SyntaxError: Unexpected reserved word
    at Loader.moduleStrategy (internal/modules/esm/translators.js:122:18)
    at async link (internal/modules/esm/module_job.js:42:21)
users-iMac-2:backend NEHAL$ 

在启动项目后,是否运行了“npm i”命令? - medilies
根据 Laravel 9 文档,为了在 Laravel 中使用 Vite,您必须确保已安装 Node.js (16+) 和 NPM。对于使用 Windows 7 的开发人员,我建议阅读 这个问题 - hamid-davodi
5个回答

18

遇到同样的问题。将 Node 升级到 v16.16.0 后,问题得以解决。


非常感谢,你让我的一天变得更美好。我将Node从12v升级到18v。 - Moh Alaraabi

10
我遇到了同样的问题; 你操作系统上安装的 NodeJS 版本与 vite 不兼容; 我的版本是 v12.22.9; 请升级您的版本。
如果您使用基于 Debian 的操作系统,请运行以下命令。
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

@X 47 48 - IR,你测试过使用Node v12.22.9吗?它可以正常工作吗?我在我的Windows 7上有Node v13.14.0,并且遇到了相同的错误。你有什么解决方案吗?因为据我所知,更新版本的Node不适用于Windows 7。 - hamid-davodi
尝试使用Docker(它独立于操作系统);我已经将所有东西都容器化了。跟上新更新是如此容易。 - X 47 48 - IR
谢谢,这对我很有效,我正在使用 Docker。 - MT_Shikomba
1
我使用 Node 版本管理器(https://github.com/nvm-sh/nvm),可以更轻松地在所需的版本之间切换。 - user281681
太棒了!似乎有一个新版本已经发布。我认为尝试这种方法的人也应该检查最新版本。(在以下官方页面中使用Ctrl+F“setup_”以了解最新版本)https://github.com/nodesource/distributions - Exis

2

由于您使用的是较低版本的 Nodejs,因此您可以安装多个Nodejs版本并在它们之间进行切换。在我的情况下,我安装了

v14.0.0
v16.0.0
v18.0.0

在您的情况下,您应该使用版本v16.0.0v18.0.0,以管理员身份运行终端,并运行以下命令来使用特定版本:
nvm use v18.0.0

然后再次运行命令

npm run dev

它可以无任何问题地运行


1

主要是安装像v16/v18这样的Node.js版本,这样你就能在Ubuntu上摆脱错误信息了。

Err:10 https://ppa.launchpadcontent.net/certbot/certbot/ubuntu jammy Release
  404  Not Found [IP: 2620:2d:4000:1::3e 443]
Reading package lists... Done
W: https://repos.insights.digitalocean.com/apt/do-agent/dists/main/InRelease: Key is , see the DEPRECATION section in apt-key(8) for details.
E: The repository 'https://ppa.launchpadcontent.net/certbot/certbot/ubuntu jammy Rele
N: Updating from such a repository can't be done securely, and is therefore disabled 
N: See apt-secure(8) manpage for repository creation and user configuration details.
Error executing command, exiting

使用以下命令解决错误:

sudo apt-add-repository -r ppa:certbot/certbot

之后,下面的命令不会产生任何错误:

sudo apt update
sudo apt-get update

然后从 官方 github 存储库 安装 Nodejs。

使用 npx vite build 命令构建 Vuejs,使用 npm run build 命令构建 Npm


1

使用yarn代替npm,首先删除package-lock.json和node_modules文件夹。

rm -rf node_modules/ package-lock.json

然后运行:

yarn install 

运行构建命令:

yarn build # or yran dev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接