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

HTML5 herman 91浏览
公告:“业余草”微信公众号提供免费CSDN下载服务(只下Java资源),关注业余草微信公众号,添加作者微信:codedq,发送下载链接帮助你免费下载!
本博客日IP超过2000,PV 3000 左右,急需赞助商。
极客时间所有课程通过我的二维码购买后返现24元微信红包,请加博主新的微信号:codedq,之前的微信号好友位已满,备注:返现
饿了么大量招人,我内推!Java 方向!薪资不设上限,工作年龄不限!工作地点限魔都,可电话面试!简历,发我微信:codedq
所有面试题(java、前端、数据库、springboot等)一网打尽,请关注文末小程序
视频教程免费领

最近的跑一个 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

业余草公众号

最后,欢迎关注我的个人微信公众号:业余草(yyucao)!可加作者微信号1:xmtxtt(5000人已满),微信号2:xttblog(5000人已满),微信号3:codedq(超3800)。备注:“1”,添加博主微信拉你进微信群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作也可添加作者微信进行联系!

本文原文出处:业余草: » sh: cross-env: command not found 问题修复