gpt4 book ai didi

Angular 2 : how to resolve Error: (SystemJS) module is not defined?

转载 作者:搜寻专家 更新时间:2023-10-30 21:30:08 24 4
gpt4 key购买 nike

我是angular2的新手。我们知道在 angular2 中有一种通过相对路径引用文件的方法,它通过在组件元数据中定义 moduleId : module.id 来实现。但是,我尝试通过这种方式进行操作,但总是出现以下错误:

Error: (SystemJS) module is not defined 

我在这里建立了一个 plunker:a simple angular2 app

文件结构如下,很简单:

enter image description here

各部分内容如下:

config.js:

System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true,
module: "commonjs"
},
meta: {
'typescript': {
"exports": "ts"
}
},
paths: {
'npm:': 'https://unpkg.com/'
},
//map tells the System loader where to look for things
map: {

'app': './app',

'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',

'rxjs': 'npm:rxjs',
'typescript': 'npm:typescript/lib/typescript.js'
},
//packages defines our app package
packages: {
app: {
main: 'main.ts',
defaultExtension: 'ts'
},

rxjs: {
defaultExtension: 'js'
}
}
});

app.component.ts:

import { Component } from '@angular/core';

@Component({
moduleId: module.id,
selector: 'app',
templateUrl: 'app.component.html'
})
export class AppComponent {

}

其他文件可以引用plunker。我在 typescriptOptions 中设置了 module: "commonjs"。我的代码有什么问题吗?

最佳答案

对于systemjs,这里我应该使用__moduleName而不是module.id

关于 Angular 2 : how to resolve Error: (SystemJS) module is not defined?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41356123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com