运行命令 npm run dev 时如何解决错误

时间:2021-01-14 03:04:13

标签: laravel npm laravel-8

我使用的是 Laravel 8;我的错误如下。

<块引用>
[webpack-cli] D:\appdownloads\www\laravel_8\chaythu1\node_modules\laravel-mix\src\Mix.js:18
    static _primary = null;
                    ^

SyntaxError: Unexpected token =
    at new Script (vm.js:83:7)
    at NativeCompileCache._moduleCompile (D:\appdownloads\www\laravel_8\chaythu1\node_modules\v8-compile-cache\v8-compile-cache.js:240:18)
    at Module._compile (D:\appdownloads\www\laravel_8\chaythu1\node_modules\v8-compile-cache\v8-compile-cache.js:184:36)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787: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)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (D:\appdownloads\www\laravel_8\chaythu1\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at module.exports (D:\appdownloads\www\laravel_8\chaythu1\node_modules\laravel-mix\setup\webpack.config.js:2:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ development: `mix`
npm ERR! Exit status 2
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\Hieu\AppData\Roaming\npm-cache\_logs\2021-01-14T02_56_14_187Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ dev 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\Hieu\AppData\Roaming\npm-cache\_logs\2021-01-14T02_56_14_261Z-debug.log

1 个答案:

答案 0 :(得分:1)

首先,使用 node -v 检查您的节点版本。我猜您当前的节点版本不是最新版本。因此升级您的节点,然后使用 npm installnpm run dev 将解决您的问题。

您使用的是 Windows,所以如果您不知道如何升级,请查看 How to upgrade node.js on Windows?