非常简单的代码。但是出现错误 cannot find module '@angular/core'
。
course.component.ts
import {Component} from '@angular/core'
@Component({
selector: 'courses'
})
export class CoursesComponent{
}
typings.json
{
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
package.json
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"typings": "typings",
"postinstall": "typings install"
},
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.7",
"bootstrap": "^3.3.6",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"systemjs": "0.19.22",
"zone.js": "0.5.15"
},
"devDependencies": {
"concurrently": "^2.0.0",
"lite-server": "^2.1.0",
"typescript": "^1.7.5"
}
}
我知道这种问题已经回答过很多次了。但由于我的无知,我仍然不知道。
感谢您的帮助。
编辑
最佳答案
对我来说,这是由于没有正确选择 typescript 模块。所以我在 visual studio 项目属性中选择了相同的模块值“tsconfig.json File -> compilerOptions -> module: commonjs”。
关于angular - 在 Visual Studio Code IDE 中找不到模块 '@angular/core',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548133/