关于npm:Laravel Mix” sh:1:cross-env:not found错误”

Laravel Mix “sh: 1: cross-env: not found error”

我一直在尝试在我的项目中设置laravel mix,并遵循laravel网站上的安装指南,但始终会遇到错误。

我的package.json文件是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
 "private": true,
 "scripts": {
   "dev":"cross-env NODE_ENV=development webpack --progress --hide-modules",
   "watch":"cross-env NODE_ENV=development webpack --watch --progress --hide-modules",
   "hot":"cross-env NODE_ENV=development webpack-dev-server --inline --hot",
   "production":"cross-env NODE_ENV=production webpack --progress --hide-modules"
  },
 "devDependencies": {
   "axios":"^0.15.2",
   "bootstrap-sass":"^3.3.7",
   "jquery":"^3.1.0",
   "laravel-mix":"^0.4.0",
   "lodash":"^4.16.2",
   "vue":"^2.0.1"
  },
 "name":"Code",
 "version":"1.0.0",
 "main":"webpack.mix.js",
 "directories": {
   "test":"tests"
  },
 "dependencies": {
   "ansi-regex":"^2.1.1",
   "ansi-styles":"^2.2.1",
   "axios":"^0.15.3",
   "babel-core":"^6.24.1",
   "babel-code-frame":"^6.22.0",
   "babel-generator":"^6.24.1",
   "babel-messages":"^6.23.0",
   "babel-helpers":"^6.24.1",
   "babel-register":"^6.24.1",
   "babel-template":"^6.24.1",
   "babylon":"^6.17.0",
   "balanced-match":"^0.4.2",
   "babel-runtime":"^6.23.0",
   "babel-types":"^6.24.1",
   "babel-traverse":"^6.24.1",
   "brace-expansion":"^1.1.7",
   "bootstrap-sass":"^3.3.7",
   "chalk":"^1.1.3",
   "convert-source-map":"^1.5.0",
   "concat-map":"^0.0.1",
   "core-js":"^2.4.1",
   "cross-env":"^3.2.4",
   "detect-indent":"^4.0.0",
   "esutils":"^2.0.2",
   "escape-string-regexp":"^1.0.5",
   "follow-redirects":"^1.0.0",
   "globals":"^9.17.0",
   "has-ansi":"^2.0.0",
   "home-or-tmp":"^2.0.0",
   "is-finite":"^1.0.2",
   "invariant":"^2.2.2",
   "json5":"^0.5.1",
   "js-tokens":"^3.0.1",
   "jquery":"^3.2.1",
   "jsesc":"^1.3.0",
   "laravel-mix":"^0.4.0",
   "lodash":"^4.17.4",
   "loose-envify":"^1.3.1",
   "mkdirp":"^0.5.1",
   "minimatch":"^3.0.3",
   "minimist":"^0.0.8",
   "number-is-nan":"^1.0.1",
   "os-homedir":"^1.0.2",
   "os-tmpdir":"^1.0.2",
   "path-is-absolute":"^1.0.1",
   "private":"^0.1.7",
   "regenerator-runtime":"^0.10.3",
   "repeating":"^2.0.1",
   "slash":"^1.0.0",
   "source-map":"^0.5.6",
   "source-map-support":"^0.4.14",
   "strip-ansi":"^3.0.1",
   "trim-right":"^1.0.1",
   "to-fast-properties":"^1.0.2",
   "vue":"^2.3.0"
  },
 "keywords": [],
 "author":"",
 "license":"ISC",
 "description":""
}

运行npm run命令时出现的错误是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
> [email protected] dev /home/vagrant/Code
> cross-env NODE_ENV=development webpack --progress --hide-modules

sh: 1: cross-env: not found

npm ERR! Linux 4.4.0-51-generic
npm ERR! argv"/usr/local/bin/node""/usr/local/bin/npm""run""dev"
npm ERR! node v7.8.0
npm ERR! npm  v4.2.0
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] dev: `cross-env NODE_ENV=development webpack --progress --hide-modules`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] dev script 'cross-env NODE_ENV=development webpack --progress --hide-modules'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the Code package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     cross-env NODE_ENV=development webpack --progress --hide-modules
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs Code
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls Code
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vagrant/.npm/_logs/2017-04-28T17_24_11_458Z-debug.log

我正在一个无聊的盒子中运行我的项目,而我正在运行laravel 5.4。


您需要使cross-env全局运行,而不是将其包含在项目中。

运行

$ sudo npm install --global cross-env


首先检查是否安装了交叉环境模块。如果没有,请运行:

npm install cross-env

之后,您需要转到node_modules文件夹。
然后找到cross-env文件夹。进入并找到cross-env.js

在我的情况下是node_modules/cross-env/dist/bin/cross-env.js

您需要在package.json文件的scripts部分中将路径更改为cross-env.js

1
2
3
4
5
6
7
8
9
10
11
12
{
 "private": true,
 "scripts": {
   "dev":"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_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",
   "hot":"node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
   "production":"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"
  },

........

}


运行:

1
npm install

然后重试。


n


有两种方法可以解决此错误。

  • 删除node_modules文件夹,然后再次执行npm install
    如果无法解决,则:

  • 您可以通过触发

    作为dev dependency进行安装

npm install --save-dev cross-env

如果无法解决,则:

  • 全局安装cross-env作为npm install --g cross-env
    它将安装在\\\\ Users \\
    绿洲\\
    pm模块。然后,我建议您可以关闭外壳并再次打开它


    n


    n


    n


    n


    您确实需要检查是否安装了交叉环境模块。如果没有,请运行:

    1
    npm install cross-env

    但是您需要将其识别为"命令"。按照接受的答案提出的路径打补丁(或者是?)使我走得更远,但仍然给我一个错误。

    对我来说,解决方案是重新加载流浪者" vagrant reload --provision",并重置我的ssh / putty会话。