首次使用角度CLI运行“ng serve”不能正确编译并给出错误
所以我试图以角度开始我的第一个项目。
并且每次它都不会编译就像它不会做ng serve
并且没有错误地完成它,很难解释我希望你原谅我的那个。
基本上,我在Windows 10 Pro 64bit上运行node-v9.1.0和npm-v5.5.1
我使用的命令是npm install -g @angular/cli
&ng new ngvic
和cd进入文件夹并使用ng serve
。
Then I get this error:
λ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2017-11-21T09:53:09.965Z
Hash:
Time: 2522ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 3.49 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 1.19 kB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 9.02 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 853 kB [initial] [rendered]
ERROR in C:/Users/USERNAME/Documents/sites/ngvic/src/main.ts
Module build failed: Error: C:\Users\USERNAME\Documents\sites\ngvic\src\main.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (C:\Users\USERNAME\Documents\sites\ngvic\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:619:23)
at plugin.done.then (C:\Users\USERNAME\Documents\sites\ngvic\node_modules\@ngtools\webpack\src\loader.js:467:39)
at <anonymous>
@ multi webpack-dev-server/client?:0 ./src/main.ts
ERROR in C:/Users/USERNAME/Documents/sites/ngvic/src/polyfills.ts
Module build failed: Error: C:\Users\USERNAME\Documents\sites\ngvic\src\polyfills.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (C:\Users\USERNAME\Documents\sites\ngvic\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:619:23)
at plugin.done.then (C:\Users\USERNAME\Documents\sites\ngvic\node_modules\@ngtools\webpack\src\loader.js:467:39)
at <anonymous>
@ multi ./src/polyfills.ts
webpack: Failed to compile.
And this is the ng -v
Angular CLI: 1.5.3
Node: 9.1.0
OS: win32 x64
Angular: 5.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.5.3
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.3
@schematics/angular: 0.1.5
typescript: 2.4.2
webpack: 3.8.1
希望任何人都可以提供帮助。提前致谢。
Edit: Added tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
},
"include": [
"main.ts"
]
}
Edit 2: npm install
warns
λ npm install
npm WARN [email protected] requires a peer of @angular/compiler@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
added 115 packages in 7.541s
回答如下:
尝试仅在终端中运行npm install
。在我的第一个有角度的项目中,这解决了我的问题
首次使用角度CLI运行“ng serve”不能正确编译并给出错误
所以我试图以角度开始我的第一个项目。
并且每次它都不会编译就像它不会做ng serve
并且没有错误地完成它,很难解释我希望你原谅我的那个。
基本上,我在Windows 10 Pro 64bit上运行node-v9.1.0和npm-v5.5.1
我使用的命令是npm install -g @angular/cli
&ng new ngvic
和cd进入文件夹并使用ng serve
。
Then I get this error:
λ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2017-11-21T09:53:09.965Z
Hash:
Time: 2522ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 3.49 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 1.19 kB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 9.02 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 853 kB [initial] [rendered]
ERROR in C:/Users/USERNAME/Documents/sites/ngvic/src/main.ts
Module build failed: Error: C:\Users\USERNAME\Documents\sites\ngvic\src\main.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (C:\Users\USERNAME\Documents\sites\ngvic\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:619:23)
at plugin.done.then (C:\Users\USERNAME\Documents\sites\ngvic\node_modules\@ngtools\webpack\src\loader.js:467:39)
at <anonymous>
@ multi webpack-dev-server/client?:0 ./src/main.ts
ERROR in C:/Users/USERNAME/Documents/sites/ngvic/src/polyfills.ts
Module build failed: Error: C:\Users\USERNAME\Documents\sites\ngvic\src\polyfills.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (C:\Users\USERNAME\Documents\sites\ngvic\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:619:23)
at plugin.done.then (C:\Users\USERNAME\Documents\sites\ngvic\node_modules\@ngtools\webpack\src\loader.js:467:39)
at <anonymous>
@ multi ./src/polyfills.ts
webpack: Failed to compile.
And this is the ng -v
Angular CLI: 1.5.3
Node: 9.1.0
OS: win32 x64
Angular: 5.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.5.3
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.3
@schematics/angular: 0.1.5
typescript: 2.4.2
webpack: 3.8.1
希望任何人都可以提供帮助。提前致谢。
Edit: Added tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
},
"include": [
"main.ts"
]
}
Edit 2: npm install
warns
λ npm install
npm WARN [email protected] requires a peer of @angular/compiler@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
added 115 packages in 7.541s
回答如下:
尝试仅在终端中运行npm install
。在我的第一个有角度的项目中,这解决了我的问题