术语 'HOST=localhost' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称

The term 'HOST=localhost' is not recognized as the name of a cmdlet, function, script file, or operable program

我需要 运行 HOST=localhost npm 运行 start:debug 到 运行 我的服务器。此命令在我的 mac 上运行良好。在 windows cmd 和 powershell 中分别抛出这些错误。

HOST=localhost : The term 'HOST=localhost' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try 
again.
At line:1 char:1

 cmd:-
'HOST' is not recognized as an internal or external command,
operable program or batch file.

Package.json:-

"start:debug": "export NODE_PATH=`pwd`/src; node --harmony -r babel-register 
 --inspect bin/webpack-dev-server"

环境变量在 PowerShell 中的工作方式不同。您想要的更多是:

$env:HOST = 'localhost'; npm run start:debug

但请注意,从那时起,HOST 环境变量也将对其他命令生效。有 known workarounds 个,如果这对您来说是个问题。

我就是这样解决问题的。我使用的命令是为 Unix 创建的,所以我为 windows 安装了 bash shell 命令行。 这是一个指南:- https://www.windowscentral.com/how-install-bash-shell-command-line-windows-10

之后,您可以在'mnt' 目录中找到您的驱动器。要转到 C 驱动器类型:-

cd mnt/c

导航到您的项目目录。您将需要再次安装 node、yarn 和 运行 npm install。

https://nodesource.com/blog/installing-node-js-tutorial-ubuntu/

在 运行ning npm 安装之后。 运行

yarn

如果您对 npm 有任何问题,请重新启动。 这解决了我的问题,希望对您有所帮助。