typescript 在 Visual Studio Code IDE 中找不到模块“@angular/core”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44548133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cannot find module '@angular/core' in Visual Studio Code IDE
提问by Bigeyes
Pretty simple code. But having the error cannot find module '@angular/core'
.
很简单的代码。但是有错误cannot find module '@angular/core'
。
course.component.ts
course.component.ts
import {Component} from '@angular/core'
@Component({
selector: 'courses'
})
export class CoursesComponent{
}
typings.json
打字.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
包.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"
}
}
I know this kind of question has been answered many times. But due to my ignorance, I still don't know.
我知道这种问题已经回答过很多次了。但由于我的无知,我仍然不知道。
Thanks for the help.
谢谢您的帮助。
EDIT
编辑
采纳答案by Bigeyes
Originally I downloaded the quick start seed from a course on udemy.com. Obviously the course was old. And something was mess up. I have to remind the instructor to correct it
最初,我从 udemy.com 上的课程中下载了快速入门种子。显然,课程是旧的。而且有些事情搞砸了。我要提醒导师改正
Now I re-download the quick start from angular web site. The files structure is completely different from my original one. For example, it has a e2e
folder and tslint.json
. The package.json
file is under thr root folder etc. tsconfig.json
is in src
folder.
现在我从 angular 网站重新下载了快速入门。文件结构与我原来的完全不同。例如,它有一个e2e
文件夹和tslint.json
. 该package.json
文件在 thr 根文件夹下等。 tsconfig.json
在src
文件夹中。
A lot of changes, now it is working. Thanks everybody's hint.
很多变化,现在它正在工作。谢谢大家的提示。
回答by kumar chandraketu
For me it was due to the typescript module not selected correctly. So I selected same module value of "tsconfig.json File -> compilerOptions -> module: commonjs " at visual studio project properties.
对我来说,这是由于没有正确选择打字稿模块。因此,我在 Visual Studio 项目属性中选择了与“tsconfig.json File -> compilerOptions -> module: commonjs”相同的模块值。
回答by Mathias Rodriguez
It seems that your dependencies are using the package naming before RC versions.
似乎您的依赖项在 RC 版本之前使用了包命名。
This is explained here. In short, you need to add @angular/core
(and the rest of the dependencies) in the package.json
这是解释here。简而言之,您需要@angular/core
在package.json
EDIT:
package.json
编辑:
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": {
"@angular/common": "<your desired angular version>",
"@angular/compiler": "<your desired angular version>",
"@angular/core": "<your desired angular version>",
"@angular/forms": "<your desired angular version>",
"@angular/http": "<your desired angular version>",
"@angular/platform-browser": "<your desired angular version>",
"@angular/platform-browser-dynamic": "<your desired angular version>",
"@angular/router": "<your desired angular version>",
"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"
}
}
On the Angular QuickStart package.json
you have a clear picture of this example. Please, devote some time on the docs to make customizations according to your Angular version.
在 Angular QuickStart 上,package.json
您可以清楚地了解这个示例。请花一些时间在文档上根据您的 Angular 版本进行自定义。
Hope this helps.
希望这可以帮助。
回答by vikas bansal
That problem can be arised only if there doesn't exist any such file or folder So, please Look for a folder named "node_modules" which should be present at the same place where your package.json, tsconfig.json exists and then follow this node_modules-> @angular -> core
仅当不存在任何此类文件或文件夹时才会出现该问题因此,请查找名为“node_modules”的文件夹,该文件夹应该与您的 package.json、tsconfig.json 存在的位置相同,然后按照此操作node_modules-> @angular -> 核心
回答by Victor Jatobá
To me on Ionic 3 project, works just updating the typescript to the latest version
对我来说,Ionic 3 项目只是将打字稿更新到最新版本
npm i --save-dev typescript@latest
Then, run:
然后,运行:
npm update
If you have problems with ionic serve
, just run:
如果你有问题ionic serve
,只需运行:
npm install
To see more details on how to adjust VSCode IDE to "hide" this problem, see: https://code.visualstudio.com/docs/languages/typescript#_using-newer-typescript-versions
要查看有关如何调整 VSCode IDE 以“隐藏”此问题的更多详细信息,请参阅:https://code.visualstudio.com/docs/languages/typescript#_using-newer-typescript-versions