问题描述
我正在尝试使用ng serve来提高本地角度的dev env,一天前工作得很好,但是现在每次运行ng serve或npm start时都会抛出错误:
I am trying to up my local angular dev env using ng serve, it was working perfectly fine a day back, but now every time I run ng serve or npm start it throws an error:
发生未处理的异常:项目不存在."
"An unhandled exception occurred: Project does not exist."
我尝试在我的另一个项目中运行ng serve,它在那里工作.
I have tried running ng serve in one of my different project, it works there.
不确定导致此错误的原因
not sure what it causing this error
推荐答案
请确保 angular.json
中的项目名称与从包中调用的名称相匹配.json
脚本部分.
Make sure the name of the project in your angular.json
matches what is being called from your package.json
scripts section.
这就是我发现问题的方式.我收到以下错误:
This is how I discovered the problem. I was getting the following error:
An unhandled exception occurred: Project does not exist.
See "C:\Users\Adam\AppData\Local\Temp\ng-XcQsPs\angular-errors.log" for further details.
当我转到该日志文件时,我看到了:
When I went to that log file, I saw this:
[error] Error: Project does not exist.
at WorkspaceNodeModulesArchitectHost.findProjectTarget (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:94:23)
at WorkspaceNodeModulesArchitectHost.getBuilderNameForTarget (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:13:39)
at RunCommand.runSingleTarget (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular\cli\models\architect-command.js:175:55)
at RunCommand.runArchitectTarget (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular\cli\models\architect-command.js:218:35)
at RunCommand.run (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular\cli\commands\run-impl.js:14:25)
at RunCommand.validateAndRun (C:\Users\Adam\source\repos\TechScore.Express\node_modules\@angular\cli\models\command.js:134:39)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
所以我打开 node-modules-architect-host.js:94:23
并看到了:
const projectDefinition = this._workspace.projects.get(target.project);
if (!projectDefinition) {
throw new Error('Project does not exist.');
}
我不知道他们为什么在不告诉您哪个项目不存在的情况下抛出这样的错误.所以我将文件更改为这样:
I have no idea why they throw an error like this without telling you which project does not exist. So I changed the file to be like this:
throw new Error('Project does not exist. ' + target.project);
现在,当我构建时,我会收到类似这样的错误:
Now, when I build, I get an error like this instead:
An unhandled exception occurred: Project does not exist. client-app
最后,我可以看到罪魁祸首是谁!全局搜索"client-app"显示我正在 package.json
中使用它,但是我在 angular.json
中的项目是"ClientApp".将"ClientApp"的所有引用更改为"client-app"对我来说解决了这个问题.
Finally I can see who the culprit is! A global search for "client-app" showed me that it was being used from package.json
, but my project in angular.json
was "ClientApp". Changing all references of "ClientApp" to "client-app" fixed the problem for me.
这篇关于angular ng serve命令引发错误:发生未处理的异常:项目不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!