在 laravel npm 运行开发错误:

Posted

技术标签:

【中文标题】在 laravel npm 运行开发错误:【英文标题】:In laravel npm run dev errors: 【发布时间】:2018-10-05 20:00:51 【问题描述】:

我有下一个错误输出为我的 laravel 5.6 与引导项目运行 npm 命令:

$ npm run dev

> @ dev /mnt/_work_sdb8/wwwroot/lar/B4test
> npm run development


> @ development /mnt/_work_sdb8/wwwroot/lar/B4test
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

sh: 1: cross-env: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
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! spawn ENOENT
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!     /home/serge/.npm/_logs/2018-04-25T10_54_37_776Z-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 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!     /home/serge/.npm/_logs/2018-04-25T10_54_37_794Z-debug.log

文件 /home/serge/.npm/_logs/2018-04-25T10_54_37_776Z-debug.log 有:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'development' ]
2 info using npm@6.0.0
3 info using node@v9.11.1
4 verbose run-script [ 'predevelopment', 'development', 'postdevelopment' ]
5 info lifecycle @~predevelopment: @
6 info lifecycle @~development: @
7 verbose lifecycle @~development: unsafe-perm in lifecycle true
8 verbose lifecycle @~development: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/mnt/_work_sdb8/wwwroot/lar/B4test/node_modules/.bin:/usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/mnt/_work_sdb8/wwwroot/lar/B4test/node_modules/.bin:/home/serge/.composer/vendor/bin:/home/serge/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:~/.composer/vendor/bin
9 verbose lifecycle @~development: CWD: /mnt/_work_sdb8/wwwroot/lar/B4test
10 silly lifecycle @~development: Args: [ '-c',
10 silly lifecycle   'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js' ]
11 info lifecycle @~development: Failed to exec development script
12 verbose stack Error: @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
12 verbose stack spawn ENOENT
12 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack     at ChildProcess.emit (events.js:180:13)
12 verbose stack     at maybeClose (internal/child_process.js:936:16)
12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
13 verbose pkgid @
14 verbose cwd /mnt/_work_sdb8/wwwroot/lar/B4test
15 verbose Linux 4.13.0-38-generic
16 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "development"
17 verbose node v9.11.1
18 verbose npm  v6.0.0
19 error file sh
20 error code ELIFECYCLE
21 error errno ENOENT
22 error syscall spawn
23 error @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
23 error spawn ENOENT
24 error Failed at the @ development script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]

在 composer.json 中:


    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": 
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.6.*",
        "components/highlightjs": "^9.12",
        "doctrine/dbal": "^2.6",
        "intervention/image": "^2.4",
        "laracasts/utilities": "^3.0",
        "laravel/tinker": "~1.0",
        "nwidart/laravel-modules": "^3.0",
        "pusher/pusher-php-server": "^3.0",
        "spatie/laravel-backup": "^5.1",
        "wboyz/laravel-enum": "^0.2.1"
    ,
    "require-dev": 
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.7",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0",
        "barryvdh/laravel-debugbar": "^3.1",
        "laravel/dusk": "~3.0"
    ,
    "autoload": 
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": 
            "App\\": "app/",
            "Modules\\": "Modules/"
        
    ,
    "autoload-dev": 
        "psr-4": 
            "Tests\\": "tests/"
        
    ,
    "extra": 
        "laravel": 
            "dont-discover": [
            ]
        
    ,
    "scripts": 
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    ,
    "config": 
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    ,
    "minimum-stability": "dev",
    "prefer-stable": true

在 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": "npm run development -- --watch",
        "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 --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    ,
    "devDependencies": 
        "axios": "^0.18",
        "bootstrap": "^4.0.0",
        "popper.js": "^1.12",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^2.0",
        "lodash": "^4.17.4",
        "vue": "^2.5.7",
        "vue-template-compiler": "^2.5.16",
        "vue2-collapse": "^1.0.11"
    ,
    "dependencies": 
        "element-ui": "^2.3.6",
        "font-awesome": "^4.7.0",
        "fullcalendar": "^3.9.0",
        "highlight.js": "^9.12.0",
        "laravel-echo": "^1.3.5",
        "marked": "^0.3.19",
        "pusher-js": "^4.2.2",
        "v-toaster": "^1.0.3",
        "vee-validate": "^2.0.6",
        "vee-validate-laravel": "^1.0.1",
        "vue-bootstrap-datetimepicker": "^4.1.3",
        "vue-chat-scroll": "^1.2.1",
        "vue-fullcalendar": "^1.0.9",
        "vue-js-popover": "^1.1.7",
        "vue-moment": "^3.2.0",
        "vue-mouse-menu": "^1.1.0",
        "vue-nl2br": "0.0.5",
        "vue-notify-me": "^1.1.0",
        "vue-popperjs": "^1.2.6",
        "vue-router": "^3.0.1",
        "vue-select": "^2.4.0",
        "vue-simple-calendar": "^2.2.0",
        "vue-timeago": "^3.4.4",
        "vuejs-datepicker": "^0.9.29"
    

你能提示一下什么会引发错误以及如何修复它吗?

配置文件中的一些错误或什么?

非常感谢!

【问题讨论】:

【参考方案1】:

你需要安装cross-env npm 包。

npm install --save-dev cross-env

它在您的开发依赖项中列出,请确保先运行npm install

【讨论】:

【参考方案2】:

就我而言,我必须将节点升级到版本 14。

使用检查您的节点版本

node -v

然后,从NODESOURCE 安装稳定版本

基本上,

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

之后,

npm install

根据您的需要执行命令。 就我而言:

npm run dev

如果您仍然遇到问题,请尝试NPM ERROR

仅列出此错误的其他关键字:

npm 错误! @开发:mix

laravel npm 错误!代码 ELIFECYCLE laravel

错误代码 ELIFECYCLE

npm 错误! @开发脚本失败 呃!代码EACCES

错误!代码生命周期

错误!代码 EMISSINGARG

【讨论】:

【参考方案3】:

即使我使用与以前相同的最新版本的 npm,也得到了上述结果 执行 npm run dev 命令时出错。部分错误的详细信息是“npm ERR!@development: mix laravel npm ERR!code ELIFECYCLE laravel error code ELIFECYCLE mix not Recognized as internal command npm ERR!Failed at the @development script ERR!code EACCESerrors”

对我有用的解决方案:我已经卸载了全局安装的 npm,并在全局重新安装了相同的 npm,“npm run dev”运行良好。感谢您强调该问题与 npm 或不兼容的 npm 版本有关。

【讨论】:

【参考方案4】:

我什么都不需要安装,我只运行:

npm install

之后:

npm audit fix

最后:

npm audit fix --force

然后:

npm run dev

它现在正在工作。

【讨论】:

以上是关于在 laravel npm 运行开发错误:的主要内容,如果未能解决你的问题,请参考以下文章

使用 laravel 微风运行 npm 时出现节点错误

使用 laravel 5.4 在 VM 上运行开发安装错误

错误:npm run dev

如何解决 npm run dev

尝试 Laravel jetstream 但在“npm run dev”上出现错误

Laravel 5.8 npm run dev 生成 ENOENT 错误