gpt4 book ai didi

node.js - HOST 不被识别为内部或外部命令

转载 作者:行者123 更新时间:2023-12-03 12:16:23 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Setting environment variables package.json in Windows 10

(3 个回答)


去年关闭。




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

NodeJS installed

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

npm install



之后

npm start



第一个命令工作正常,但第二个命令出现以下错误
> 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

Git Bash HOST is not recognized as an internal or external command

CMD
CMD HOST is not recognized as an internal or external command

PowerShell
PowerShell HOST is not recognized as an internal or external command

最佳答案

方法一

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

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

Starting the development server...

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

Must be something to do with how npm shells out then



为了修复它,我去了 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也可以正常工作:

cross-env npm start

关于node.js - HOST 不被识别为内部或外部命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60265153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com