我想通过输入命令ng new myapp
来设置Angular项目。然后我由cd myapp
切换到那里并输入ng serve --open
。我安装了Angular以及Node,并尝试了Windows CMD和Git Bash作为CMD。通过命令ng serve --open
,会发生错误:
0% compiling
Compiling @angular/core : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
Compiling @angular/router : es2015 as esm2015
chunk {main} main.js, main.js.map (main) 60.6 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 140 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 9.73 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 2.99 MB [initial] [rendered]
Date: 2020-03-11T12:35:25.912Z - Hash: 8a7cea9d57d6e7ce1441 - Time: 45208ms
Angular Live Development Server is listening on localhost:4200, open your browser on
http://localhost:4200/
: Compiled successfully.
events.js:288
throw er; // Unhandled 'error' event
^
Error: spawn cmd ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn cmd',
path: 'cmd',
spawnargs: [ '/s', '/c', 'start', '""', '/b', '"http://localhost:4200/"' ]
如何解决此问题,以便出现Angular模板?
我的node.js版本:12.16.1。
当我输入ng版本时:
Angular CLI: 9.0.5
Node: 12.16.1
OS: win32 x64
Angular: 9.0.6
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.900.5
@angular-devkit/build-angular 0.900.5
@angular-devkit/build-optimizer 0.900.5
@angular-devkit/build-webpack 0.900.5
@angular-devkit/core 9.0.5
@angular-devkit/schematics 9.0.5
@angular/cli 9.0.5
@ngtools/webpack 9.0.5
@schematics/angular 9.0.5
@schematics/update 0.900.5
rxjs 6.5.4
typescript 3.7.5
webpack 4.41.2
答案 0 :(得分:0)
Windown 10: 此PC->“属性”->“系统保护”->“高级”选项卡->“环境变量”->“系统变量”->选择“路径”->“编辑”:
全部添加
C:\ Program Files \ Common Files \ Microsoft共享\ Microsoft在线服务
C:\ Program Files(x86)\ Common Files \ Microsoft Shared \ Microsoft Online Services
C:\ Program Files(x86)\ Common Files \ Oracle \ Java \ javapath
%SystemRoot%\ system32
%SystemRoot%
%SystemRoot%\ System32 \ Wbem
%SYSTEMROOT%\ System32 \ WindowsPowerShell \ v1.0 \
%SYSTEMROOT%\ System32 \ OpenSSH \
C:\ Program Files \ Microsoft SQL Server \ Client SDK \ ODBC \ 130 \ Tools \ Binn \
C:\ Program Files(x86)\ Microsoft SQL Server \ 140 \ Tools \ Binn \
C:\ Program Files \ Microsoft SQL Server \ 140 \ Tools \ Binn \
C:\ Program Files \ Microsoft SQL Server \ 140 \ DTS \ Binn \
C:\ Program Files(x86)\ Microsoft SQL Server \ Client SDK \ ODBC \ 130 \ Tools \ Binn \
C:\ Program Files(x86)\ Microsoft SQL Server \ 140 \ DTS \ Binn \
C:\ Program Files(x86)\ Microsoft SQL Server \ 140 \ Tools \ Binn \ ManagementStudio \
C:\ Program Files \ Microsoft SQL Server \ 120 \ Tools \ Binn \
C:\ Program Files \ Git \ cmd
C:\ Program Files \ Git \ mingw64 \ bin
C:\ Program Files \ Git \ usr \ bin
C:\ Program Files \ nodejs \
点击确定->确定->确定完成