解决Laravel使用npm run dev的时候报错“cross-env 不是内部命令”

cross-env must have updated its paths, it has "cross-env/dist/bin" not "cross-env/bin/"

in package.json
(EDIT)

    "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"

大概就是把从前的cross-env全部用node node_modules/cross-env/dist/bin/cross-env.js替换掉

下面的例子是csdn的一片文章,大概和上边一样。

 

{
    "private": true,
    "scripts": {
        "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": "npm run development -- --watch",
        "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 --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^2.0",
        "lodash": "^4.17.4",
        "popper.js": "^1.12",
        "vue": "^2.5.16"
    }
}
 
需要将laravel根目录下的packae.json中的cross-env修改
node node_modules/cross-env/dist/bin/cross-env.js  NODE_ENV=development node_modules/webpack/bin/webpack.js

 

 

 

其他外国友人是这样做的

 

You need to make cross-env working globally instead of having it in the project.

1) remove node_modules folder

2) run

npm install --global cross-env

3) remove "cross-env": "^5.0.1", from package.json file devDependencies section. Actually, you can skip this step and keep package.json intact. If you prefer.

4) run

npm install --no-bin-links

5) run

npm run dev

and see it working

P.S Tested on Windows 10 with Laravel-5.4

P.P.S Windows 10 with Laravel-5.6 does not have this problem, thus updating is an alternative solution.

大概是说在laravel根目录下执行npm run dev之前因该下载使用全局下载corss-env

然后从package.json中删除corss-env:5.0.1

之后在npm install --no-bin-links

最后在执行npm run dev。

node不怎么懂,但Laravel5.6的npm run dev我就是按照第一中做的,直接修改了package.json,因为我没有用全--global 

你可能感兴趣的:(解决Laravel使用npm run dev的时候报错“cross-env 不是内部命令”)