运行npm命令时出现ELIFECYCLE错误

时间:2020-03-25 14:29:20

标签: node.js npm

我只是使用npm --v命令检查npm版本。但是每当我运行任何npm命令时,都会出现以下错误

'CALL "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,
operable program or batch file.

我试图在Laravel项目中安装react js,因为我需要运行以下命令

当我刚运行npm命令时,出现以下错误

'CALL "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,
operable program or batch file.

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    C:\Users\Dell\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.13.7 C:\Program Files\nodejs\node_modules\npm

    npm run dev
But this command too throws error along with the above error

    'CALL "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,
    operable program or batch file.

    > @ dev C:\xampp\htdocs\laravel-react\CRUD
    > npm run development

    npm ERR! code ELIFECYCLE
    npm ERR! syscall spawn C:\Windows\system32\cmd.exe;C:\xampp\php;
    npm ERR! file C:\Windows\system32\cmd.exe;C:\xampp\php;
    npm ERR! path C:\Windows\system32\cmd.exe;C:\xampp\php;
    npm ERR! errno -4058
    npm ERR! @ dev: `npm run development`
    npm ERR! spawn C:\Windows\system32\cmd.exe;C:\xampp\php; ENOENT
    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\Dell\AppData\Roaming\npm-cache\_logs\2020-03-25T14_19_49_350Z-debug.log



I have already set up my environment variables and it seems correct to me.

**User Variable**

    C:\Users\Dell\AppData\Roaming\npm

**System Variable**

    C:\Program Files\nodejs\

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": {
        "@babel/preset-react": "^7.0.0",
        "axios": "^0.19",
        "bootstrap": "^4.0.0",
        "cross-env": "^7.0",
        "jquery": "^3.2",
        "laravel-mix": "^5.0.1",
        "lodash": "^4.17.13",
        "popper.js": "^1.12",
        "react": "^16.2.0",
        "react-dom": "^16.2.0",
        "resolve-url-loader": "^3.1.0",
        "sass": "^1.15.2",
        "sass-loader": "^8.0.0"
    }
}

我还遵循了关于Stack Overflow的一些答案,并尝试完全卸载并重新安装Node js,但这是行不通的。

即使这个https://stackoverflow.com/a/49505612/4494813也不适合我。

1 个答案:

答案 0 :(得分:0)

首先检查您的节点版本

清理缓存

然后重新安装节点模块

rm -rf node_modules

npm cache clean --force

npm i

npm run dev