为什么安装 nativescript 时 tns 不被识别为 cmdlet 的名称?

why installing nativescript gives that tns is not recognized as the name of a cmdlet?

我正在尝试安装 nativescript,当我执行 npm install 时它工作正常,但之后当我尝试时

tns doctortns create

它给了我这条信息:

The term 'tns' 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 nativescript

有人告诉我这可能与环境变量有关,但如果是这样我不确定需要做什么

我通过将 nativescript 节点模块复制到 C:\Users\username\AppData\Roaming\npm\node_modules 然后在 C:\Users\username\AppData\Roaming\npm 中创建一个名为 tns.cmd 的文件解决了这个问题,该文件具有以下内容:

@IF EXIST "%~dp0\node.exe" ( "%~dp0\node.exe" "%~dp0\node_modules\nativescript\bin\tns" %* ) ELSE ( @SETLOCAL @SET PATHEXT=%PATHEXT:;.JS;=;% node "%~dp0\node_modules\nativescript\bin\tns" %* )

然后成功了