解决办法: Vue cross-env NODE_ENV=production webpack --progress --hide-module

孔硕
2023-12-01

Vue 在本地开发的时候正常,在布到服务器的时候,运行 npm run build 提示如下错误

[root@VM_0_15_centos starve]# npm run build

> vue-test@1.0.0 build /var/www/html/starve
> cross-env NODE_ENV=production webpack --progress --hide-modules

sh: cross-env: command not found

npm ERR! Linux 3.10.0-514.26.2.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
npm ERR! node v6.17.1
npm ERR! npm  v3.10.10
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! vue-test@1.0.0 build: `cross-env NODE_ENV=production webpack --progress --hide-modules`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the vue-test@1.0.0 build script 'cross-env NODE_ENV=production 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 vue-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     cross-env NODE_ENV=production webpack --progress --hide-modules
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs vue-test
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls vue-test
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/html/starve/npm-debug.log

解决办法: 安装的时候用 npm install -D 安装开发环境
而不是 npm install

然后就可以了

[root@VM_0_15_centos starve]# npm run build 

> vue-test@1.0.0 build /var/www/html/starve
> cross-env NODE_ENV=production webpack --progress --hide-modules

Hash: c9ac6c457984b8cdaed2                                                           
Version: webpack 3.12.0
Time: 11157ms
       Asset     Size  Chunks             Chunk Names
    build.js   225 kB       0  [emitted]  main
build.js.map  1.91 MB       0  [emitted]  main
 类似资料: