node.js Laravel 5.4 'cross-env' 不被识别为内部或外部命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45034581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.4 ‘cross-env’ Is Not Recognized as an Internal or External Command
提问by Arthur Tarasov
I'm trying to run npm run devfor Laravel Mix and I get this error:
我正在尝试npm run dev为 Laravel Mix运行,但出现此错误:
> @ dev D:\projects\ptcs
> cross-env NODE_ENV=development webpack --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! @ dev: `cross-env NODE_ENV=development webpack --progress --hide-
modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev script.
I updated node.js to 6.11.0 and npm to 5.2.0, but it didn't help. I'm running Homestead on Windows 7.
我将 node.js 更新为 6.11.0,将 npm 更新为 5.2.0,但没有帮助。我在 Windows 7 上运行 Homestead。
回答by Yevgeniy Afanasyev
You need to make cross-env working globally instead of having it in the project.
您需要让 cross-env 在全球范围内工作,而不是在项目中使用它。
1) remove node_modulesfolder
1)删除node_modules文件夹
2) run
2)运行
npm install --global cross-env
npm install --global cross-env
3) remove "cross-env": "^5.0.1",from package.jsonfile devDependenciessection. Actually, you can skip this step and keep package.json intact. If you prefer.
3)"cross-env": "^5.0.1",从package.json文件devDependencies部分删除。实际上,您可以跳过此步骤并保持 package.json 完好无损。若你宁可。
4) run
4)运行
npm install --no-bin-links
npm install --no-bin-links
5) run
5)运行
npm run dev
npm run dev
and see it working
并看到它工作
P.S Tested on Windows 10 with Laravel-5.4
PS 在 Windows 10 上使用 Laravel-5.4 进行测试
P.P.S Windows 10 with Laravel-5.6 does not have this problem, thus updatingis an alternative solution.
带有 Laravel-5.6 的 PPS Windows 10 没有这个问题,因此更新是一个替代解决方案。
回答by flik
First run:
第一次运行:
rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
Then run the command
然后运行命令
npm install cross-env
npm install
and then you can also run
然后你也可以运行
npm run dev
回答by collin
Following these steps solved my problem.
按照这些步骤解决了我的问题。
- Delete
node_modulesdirectory - Delete
package-lock.jsonfile - Start command prompt as Administrator <- important
- Run
npm install - Run
npm run dev
- 删除
node_modules目录 - 删除
package-lock.json文件 - 以管理员身份启动命令提示符<- 重要
- 跑
npm install - 跑
npm run dev
回答by Naveed Ali
You are getting the error because you might not have run the command npm installfirst.
您收到错误是因为您可能没有先运行该命令npm install。
i.e.
First, run npm installand then npm run dev
即首先运行npm install然后npm run dev
回答by Hafez Divandari
According to this issue comment, editing cross-envpath will fix the problem. Change cross-envto node node_modules/cross-env/dist/bin/cross-env.jsin package.jsonlike this:
根据此问题评论,编辑cross-env路径将解决问题。更改cross-env到node node_modules/cross-env/dist/bin/cross-env.js在package.json这样的:
"dev": "npm run development",
"development": "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": "npm run watch -- --watch-poll",
"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",
"prod": "npm run production",
"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"
回答by Alexandre Siqueira
There is the same problem in Linux OS. The issue is related on Windows OS, but Homestead is a Ubuntu VM, and the solution posted works strongly good in others SO. I applied the commands sugested by flik, and the problems was solved. I only used the following commands
Linux 操作系统中也存在同样的问题。该问题与 Windows 操作系统有关,但 Homestead 是一个 Ubuntu VM,并且发布的解决方案在其他人中非常有效。我应用了 flik 建议的命令,问题解决了。我只使用了以下命令
I only used the following commands
我只使用了以下命令
rm -rf node_modules
npm cache clear --force
After
后
npm install cross-env
npm install
npm run watch
It's working fine on linux Fedora 25.
它在 Linux Fedora 25 上运行良好。
回答by Luca C.
For me simply run:
对我来说,只需运行:
npm install cross-env
was enough
够了
回答by only4
Before try running npm run devplease run npm install --no-bin-linksin the project directory, this will install all required packages.
Also check this link for compiling instruction.
https://laravel.com/docs/5.4/mix
在尝试运行之前,npm run dev请npm install --no-bin-links在项目目录中运行,这将安装所有必需的包。另请检查此链接以获取编译说明。
https://laravel.com/docs/5.4/mix
Also double check in your conffile, wherever you find something like this
还要仔细检查你的conf文件,无论你在哪里找到这样的东西
(something)/cross-env/bin/(something)
(something)/cross-env/bin/(something)
change it to
将其更改为
(something)/cross-env/dist/bin/(something)
(something)/cross-env/dist/bin/(something)
If you are using homestead, in package.jsonpaste this
如果您使用的是宅基地,请package.json粘贴此内容
{
"private": true,
"scripts": {
"dev": "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": "cross-env 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": "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",
"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.8.1",
"lodash": "^4.17.4",
"vue": "^2.1.10"
}
}
Also check this link https://github.com/JeffreyWay/laravel-mix/issues/478
另请检查此链接 https://github.com/JeffreyWay/laravel-mix/issues/478
回答by Ahmad Rasyid Salim
I think this log entry Local package.json exists, but node_modules missing, did you mean to install?has gave me the solution.
我认为这个日志条目Local package.json 存在,但是缺少 node_modules,您是要安装吗?给了我解决方案。
npm install && npm run dev
回答by serdarsenay
Simply try running npm install/ yarnetc first before running npm start/ yarnstart as @only4 mentioned, if you see this problem, as it means your .envis not in sync with your package.json, i.e. you installed a package but not quite configured it or other way around
只需在运行/启动之前先尝试运行npm install/ yarnetc ,如@only4 提到的那样,如果您看到此问题,因为这意味着您与您的.npm startyarn.envpackage.json

