'cross-env' 未被识别为内部或外部命令,

'cross-env' is not recognized as an internal or external command,

伙计们,你能帮我解决这个问题吗?我的 Laravel Mix 运行 npm 运行 dev 遇到了麻烦。我点击了下面的链接,但仍然存在错误。我的 OS 有问题吗?我试图删除 node_modules、运行 npm install --global cross-env。 运行 NPM 再次安装。

https://github.com/JeffreyWay/laravel-mix/issues/478

这是我的版本:

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

'cross-env' is not recognized as an internal or external command,
operable program or batch file.
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.
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\Garciano\AppData\Roaming\npm-cache\_logs18-02-17T10_08_34_901Z-debug.log

您是否尝试按照链接的 dwoodward on the Github issue 的建议指定 cross-env 的路径。这进入你的 package.json 文件:

"dev": "node node_modules/cross-env/dist/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/dist/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",
"watch-poll": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --watch-poll --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "node node_modules/cross-env/dist/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/dist/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"

这在 Laravel 的较新版本中可能已更改,但要点是您应该将 cross-env 更改为 node_modules/cross-env/dist/bin/cross-env.js

首先,运行:

rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force

然后运行命令

npm install cross-env

npm install 

然后你也可以运行

npm run dev

尝试将 npm bin 目录添加到您的系统路径 例如 C:\Users\DELL\AppData\Local\Yarn\bin

我通过卸载节点然后运行以下命令解决了这个问题。

npm install -d