简体   繁体   English

Angular2智能配置错误。找不到模块“ @ angular / core”

[英]Angular2 intelliJ config error.. Cannot find module '@angular/core'

I am new to Angular2. 我是Angular2的新手。 I am following the Tutorial Angular2 by Example . Tutorial Angular2 by Example This is the first simple tutorial called guess-the-number 这是第一个简单的教程,称为数字猜测

I used the code exactly as described in github provided example https://github.com/chandermani/angular2byexample/tree/master/guessthenumber . 我使用的代码完全与github提供的示例https://github.com/chandermani/angular2byexample/tree/master/guessthenumber中描述的代码相同。

It loads fine in the browser. 它可以很好地在浏览器中加载。 It is with IntelliJ setup where I'm having issues. 问题出在IntelliJ设置中。

IntelliJ is returning the following error.. as seen in the screenshot. IntelliJ返回以下错误..如屏幕快照所示。 Cannot find module '@angular/core' 找不到模块'@ angular / core'

在此处输入图片说明

My properties file is as follows 我的属性文件如下

systemjs.config.js

System.config({
map : {
    'app': 'app',
    'rxjs': 'https://unpkg.com/rxjs@5.0.0-beta.12',
    '@angular/common': 'https://unpkg.com/@angular/common@2.0.0',
    '@angular/compiler': 'https://unpkg.com/@angular/compiler@2.0.0',
    '@angular/core': 'https://unpkg.com/@angular/core@2.0.0',
    '@angular/platform-browser': 'https://unpkg.com/@angular/platform-browser@2.0.0',
    '@angular/platform-browser-dynamic': 'https://unpkg.com/@angular/platform-browser-dynamic@2.0.0'
},
packages:{
    'app':  { main: 'main.ts',  defaultExtension: 'ts' },
    '@angular/common': { main: 'bundles/common.umd.js', defaultExtension: 'js' },
    '@angular/compiler': { main: 'bundles/compiler.umd.js', defaultExtension: 'js' },
    '@angular/core': { main: 'bundles/core.umd.js', defaultExtension: 'js' },
    '@angular/platform-browser': { main: 'bundles/platform-browser.umd.js', defaultExtension: 'js' },
    '@angular/platform-browser-dynamic': { main: 'bundles/platform-browser-dynamic.umd.js', defaultExtension: 'js' },
},
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'typescript',
typescriptOptions: {
    emitDecoratorMetadata: true
}
});

My thoughts on a potential solution? 我对潜在解决方案有何想法?

  1. currently loads the module from https://unpkg.com/@angular/core@2.0.0 but IntelliJ would prefer it to be loaded from a file on the computer? 当前从https://unpkg.com/@angular/core@2.0.0加载模块,但是IntelliJ希望从计算机上的文件加载该模块吗? Should I host files locally? 我应该在本地托管文件吗?

  2. Intellij does not know about the systemjs.config.js file? Intellij不知道systemjs.config.js文件吗? Do I need to create a tsconfig.json file? 我需要创建一个tsconfig.json文件吗? that Intellij can understand? Intellij可以理解吗?

The errors come from TS compiler. 错误来自TS编译器。 And yes, just like Idea itself, it can't find @angular modules by CDN references in your system config: it needs modules being available locally in your project (installed via npm - see https://angular.io/docs/ts/latest/guide/setup.html , for example). 是的,就像Idea本身一样,它无法在系统配置中通过CDN引用找到@angular模块:它需要在项目中本地可用的模块(通过npm安装-参见https://angular.io/docs/ts /latest/guide/setup.html )。 Configuration like yours will only work when using browser based compilation 像您这样的配置仅在使用基于浏览器的编译时有效

Yes, I think you need to create tsconfig.json, 是的,我认为您需要创建tsconfig.json,

And turn on typescript compiler in IntelliJ Settings 并在IntelliJ设置中打开Typescript编译器

在此处输入图片说明

Also this answer can help you too 这个答案也可以帮助您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM