[英]Angular 2 - Can't find module angular/core
I'm coming here and asking a question that has been already answered in another post, but all the solutions don't work. 我要来这里问一个已经在另一篇文章中得到回答的问题,但是所有解决方案都行不通。 So, I'm creating a new angular2 app from the quickstart folder of angular website.
因此,我正在从angular网站的quickstart文件夹中创建一个新的angular2应用。
I've done npm install
and all is okay, I have my node_modules folder at the root. 我已经完成了
npm install
,一切都还好,我的node_modules文件夹位于根目录。
But, when I'm doing ng serve
, this is the error I got : 但是,当我做
ng serve
,这是我得到的错误:
ERROR in angular/src/app/app.component.ts (1,27): Cannot find module '@angular/core'.
ERROR in angular/src/app/app.component.ts (8,14): Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
ERROR in angular/src/app/app.module.ts (1,31): Cannot find module '@angular/platform-browser'.
ERROR in angular/src/app/app.module.ts (2,26): Cannot find module '@angular/core'.
ERROR in angular/src/app/app.module.ts (16,14): Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
ERROR in angular/src/main.ts (1,32): Cannot find module '@angular/core'.
ERROR in angular/src/main.ts (2,40): Cannot find module '@angular/platform-browser-dynamic'.
This is my folder structure : 这是我的文件夹结构:
And this is my tsconfig.json : 这是我的tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"../node_modules/@types/"
]
},
"compileOnSave": true,
"exclude": [
"node_modules/*",
"**/*-aot.ts"
]
}
Edit : 编辑:
This is my app.module.ts
: 这是我的
app.module.ts
:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
I went through my tsconfig.json file and found that your tsconfig.json differs from mine. 我浏览了tsconfig.json文件,发现您的tsconfig.json与我的不同。 The "include" & "exclude" key values pairs are different.
“包含”和“排除”键值对不同。 Have a look.
看一看。
tsconfig.json tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
This is my tsconfig. 这是我的tsconfig。 maybe it helps:
也许有帮助:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.