Laravel“ npm run dev”抛出“ const envVars = {... process.env}”意外的令牌问题

时间:2020-08-16 14:32:28

标签: laravel npm laravel-mix

我正在研究Laravel项目。我已经从头开始安装了Laravel项目。我的笔记本电脑的操作系统是Windows 10。 我已经安装了npm install。然后我运行“ npm run dev”。然后出现以下错误。

> @ development C:\Users\Acer\Desktop\LaravelProjects\PatheinDirectory
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

C:\Users\Acer\Desktop\LaravelProjects\PatheinDirectory\node_modules\cross-env\src\index.js:87
  const envVars = {...process.env}
                   ^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Acer\Desktop\LaravelProjects\PatheinDirectory\node_modules\cross-env\src\bin\cross-env.js:3:18)
npm ERR! code ELIFECYCLE
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Acer\AppData\Roaming\npm-cache\_logs\2020-08-16T14_19_31_375Z-debug.log

我尝试删除node_modules文件夹,然后尝试再次运行npm run dev。它没有用。

我也尝试在删除了node_modules文件夹后运行以下命令。

npm install --global cross-env

它也不起作用。我该如何解决?

2 个答案:

答案 0 :(得分:0)

运行npm cache clean,然后重试

答案 1 :(得分:0)

尝试更新npm。我遇到了同样的错误,对我有用。

如果您使用的是nvm,请阅读here有关更新的信息