gpt4 book ai didi

javascript - 尝试在 Windows 上执行 package.json 中的脚本会引发 JScript 错误

转载 作者:行者123 更新时间:2023-11-28 06:02:10 24 4
gpt4 key购买 nike

所以我正在尝试构建 javascriptair/site。在 package.json 中,有一个 npm 脚本指向 javascript“命令”package-scripts。找到该存储库 https://github.com/kentcdodds/p-s 。在 Windows 中,它会因 JScript 错误而出错。

Script: C:[path_to_code]\package-scripts.js
Line: 2
Char: 1
Error: Syntax error
Code: 800A03EA
Source: Microsoft JScript compilation error

所以在package.json中,它有这样的内容

"scripts": {
"start": "package-scripts"
}

如果我将 package.json 更改为以下内容:

"scripts": {
"start": "package-scripts.cmd"
}

我可以启动服务器。所以我的问题是,为什么会发生这种情况,以及我们如何更改 package.json 以使用相同的命令使其跨平台。

最佳答案

此处指出了原因和解决方法:https://github.com/javascriptair/site/issues/98#issuecomment-404420108

So the problem is there is a js file in the root of repo with the same base name as binary. And npm on windows first tries to run it as binary instead of looking into './node_modules/.bin' So to workaround an issue just remove .JS from PATHEXT environment variable and restart

我遇到了同样的问题:当包的根目录中有 tslint.js 文件并且 package.json 中的 npm 脚本只调用 tslint,jscript 由 npm 而不是 Node 触发,导致弹出“Microsoft JScript 编译错误”。从 PATHEXT 中删除 .js 会有所帮助。

关于javascript - 尝试在 Windows 上执行 package.json 中的脚本会引发 JScript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37192508/

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