gpt4 book ai didi

node.js - 当我运行 "npm run ng new app"时,任何人都可以解释这个错误吗?

转载 作者:行者123 更新时间:2023-12-02 14:09:25 25 4
gpt4 key购买 nike

所以我第一次尝试制作一个新的 Angular 应用程序,并使用 npm i -g @angular/cli 安装它。当我尝试使用 npm run ng new app 制作新应用程序时,它给出了以下错误:

npm ERR! path E:\ddii\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'E:\ddii\package.json'
npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users...\AppData\Roaming\npm-cache_logs\2018-09-10T20_22_50_118Z-debug.log

enter image description here enter image description here

最佳答案

我自己很难找到这个答案,因为这个问题的其他答案没有解决真正的根本问题。

所有其他答案都建议使用 (npm i -g ...) 全局安装 ng ,其副作用是到 ng 的符号链接(symbolic link)将出现在您的路径。

根据OP的问题,我承认他很可能试图从全局安装的ng构建一个新的Angular应用程序。所以这可以解决 90% 的人的问题,而且一切都很好。

但是,我想使用本地安装的 ng,这就是为什么我的 package.json 中有一个 npm-script对于它:

{
...
"scripts": {
...
"ng": "ng",
...
}

如果这描述了您的用例,就像我的一样,那么请继续阅读。

npm run ng update 对我来说成功了,而其他具有更多参数的更复杂的命令(包括命令行开关)则彻底失败(npm run ng -- update @angular/cli - -仅迁移 tslint-version-6)。

答案在于,您必须使用 -- 分隔传递给 npm run-script 的参数的开始位置(请参阅 https://stackoverflow.com/a/14404223/1438576 ):

npm run ng -- update @angular/cli --migrate-only tslint-version-6

因此,在 OP 的情况下,假设他已经在本地安装了带有 package.json 的 ng 副本(我承认这是值得怀疑的),他可以这样做:

npm run ng -- new app

无论如何,希望这对其他人有帮助。

关于node.js - 当我运行 "npm run ng new app"时,任何人都可以解释这个错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52265270/

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