【问题标题】:HOST is not recognized as an internal or external command [duplicate]HOST 未被识别为内部或外部命令 [重复]
【发布时间】:2020-06-01 13:04:48
【问题描述】:

使用 ReactJS 和 NodeJS 项目和 install NodeJS 克隆 Git 存储库后

想在浏览器中查看结果,因此必须在包含 package.json 的根文件夹中运行

npm 安装

之后

npm 开始

第一个命令运行良好,但第二个出现以下错误

> HOST=0.0.0.0 PORT=8000 ./node_modules/.bin/react-scripts start
'HOST' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ...: `HOST=0.0.0.0 PORT=8000 ./node_modules/.bin/react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ... start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:

package.json 有以下内容

"scripts": {
  "start": "HOST=0.0.0.0 PORT=8000 ./node_modules/.bin/react-scripts start",

使用 Git Bash、CMD 和 PowerShell 进行测试,并不断收到相同的错误,如下图所示

Git Bash

CMD

PowerShell

【问题讨论】:

  • 我希望它在 cmd 和 powershell 上失败,但这应该适用于 bash AFAIK
  • @Quentin 是的,我也认为它会起作用,但它没有......
  • @Quentin 刚刚添加了图片来证明我刚才所说的。
  • 一定与npm 的炮击方式有关
  • 找到一个重复项。使用cross-env 包。

标签: node.js reactjs


【解决方案1】:

方法一

如果我运行(不使用 npm 包装脚本)

HOST=0.0.0.0 PORT=8000 ./node_modules/.bin/react-scripts start

它工作正常。正如昆汀所说,

一定与 npm 的输出方式有关

为了修复它,我去了 package.json 并将“启动”脚本更改为

"start": "./node_modules/.bin/react-scripts start",

然后npm start 工作正常。


方法二

使用cross-env 包。

为此使用以下命令安装它

npm i cross-env

然后转到package.json并将其更改为

"start": "cross-env ./node_modules/.bin/react-scripts start",

然后运行npm start 也可以正常工作:

【讨论】:

    猜你喜欢
    • 2016-01-31
    • 2021-12-06
    • 2015-08-07
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 2013-10-11
    • 2013-01-25
    相关资源
    最近更新 更多