sh: cross-env: command not found 问题修复

最近的跑一个 nodejs 项目时遇到了问题,很多前端都不知道如何下手解决!

我这个后端老司机,无奈之下,一顿百度谷歌,最终找到解决方案。前端也并不是不可跨越的。。。

错误产生的原因是,项目中配置了 cross-env APP_TYPE=site PORT=8888 umi dev。

{
  "name": "",
  "version": "2.5.2",
  "description": "An out-of-box UI solution for enterprise applications",
  "private": true,
  "scripts": {
    "presite": "cd functions && npm install",
    "start": "cross-env APP_TYPE=site PORT=8888 umi dev"
    // ....
  }
}

然后在运行 npm run dev 时报错了。

> Code@1.0.0 dev /User/xtt/Code
> cross-env APP_TYPE=site PORT=8888 umi dev

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! Code@1.0.0 dev: `cross-env APP_TYPE=site PORT=8888 umi dev`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the Code@1.0.0 dev script 'cross-env APP_TYPE=site PORT=8888 umi dev'.
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 APP_TYPE=site PORT=8888 umi dev
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!     /User/xtt/.npm/_logs/2020-04-28T17_24_11_458Z-debug.log

解决办法很简单,安装一下 cross-env 即可。

npm install cross-env --save-dev

sh: cross-env: command not found 问题修复

: » sh: cross-env: command not found 问题修复

原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/251110.html

(0)
上一篇 2022年5月2日
下一篇 2022年5月2日

相关推荐

发表回复

登录后才能评论