【问题标题】:"npm run dev" not working on Windows“npm run dev”无法在 Windows 上运行
【发布时间】:2020-11-29 23:37:44
【问题描述】:

Laravel 版本:5.4.21

PHP 版本:7.1.1

节点 v4.4.5

npm v4.5.0

npm 命令在 Windows(本例中为 Windows 7)上完全损坏,每当我运行 npm run dev 时,都会出现以下错误:

> @ dev E:\xampp\htdocs\laravelblog
> npm run development


> @ development E:\xampp\htdocs\laravelblog
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

E:\xampp\htdocs\laravelblog\node_modules\laravel-mix\setup\webpack.config.js:1
(function (exports, require, module, __filename, __dirname) { let path = require('path');
                                                              ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at requireConfig (E:\xampp\htdocs\laravelblog\node_modules\webpack\bin\convert-argv.js:96:18)
    at E:\xampp\htdocs\laravelblog\node_modules\webpack\bin\convert-argv.js:109:17
    at Array.forEach (native)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
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 '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! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     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! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls
npm ERR! There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\winuser-pc\AppData\Roaming\npm-cache\_logs\2017-04-29T18_27_27_864Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev script 'npm run development'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run development
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls
npm ERR! There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\winuser-pc\AppData\Roaming\npm-cache\_logs\2017-04-29T18_27_27_938Z-debug.log

我试过默认package.json

{
  "private": true,
  "scripts": {
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  "devDependencies": {
    "axios": "^0.15.3",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^3.2.3",
    "jquery": "^3.1.1",
    "laravel-mix": "0.*",
    "lodash": "^4.17.4",
    "vue": "^2.1.10"
  }
}

我还尝试了来自互联网的其他帮助,比如这个

"scripts": {
    "dev": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },

指导我这里出了什么问题。为什么它不起作用

【问题讨论】:

  • 尝试带有--use_strict标志的节点
  • 或者如果可能的话安装最新的Node 6.x,如果没有,使用上面建议的严格模式,this answer也是相关的
  • @priyesh-kumar 我是开发新手。你能指导我如何使用这个--use_strict 标志
  • 在您的 package.json 文件中写入 "dev": "node --use_strict ...."。它将消除上述错误,但可能会引入新错误,因为它使用严格标志运行所有代码。
  • @priyesh-kumar 我试过了。它没有奏效。 "dev": "node --use_strict cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",

标签: php node.js laravel npm


【解决方案1】:

每个人 - 如果你没有找到“cross-env”,请执行 npm install cross-env -D,然后确保更新 package.json 中的 npm 脚本以引用 cross-env,而不是跨环境的完整 node_modules 路径。

【讨论】:

    【解决方案2】:

    我面临同样的问题并克服了 并忽略节点版本管理器NVM

    npm i -g yarn

    yarn run dev

    【讨论】:

      猜你喜欢
      • 2023-01-02
      • 2020-12-27
      • 2022-08-05
      • 1970-01-01
      • 2019-11-03
      • 2021-09-09
      • 1970-01-01
      • 2022-07-17
      • 2018-12-12
      相关资源
      最近更新 更多