gpt4 book ai didi

javascript - 在 Angular2 应用程序中找不到名称模块

转载 作者:数据小太阳 更新时间:2023-10-29 04:17:59 29 4
gpt4 key购买 nike

我正在使用 angular-cli 来运行我的 typescript 驱动的 angular2 应用程序。我有一个 AppComponent 定义如下:

import { Component } from '@angular/core';
import { ServersListComponent } from './servers-list/servers-list.component';

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

}

angular-cli 无法编译此文件,因为它在 moduleId: module.id 行中提示此问题主题中提到的错误。

我的 tsconfig.json 文件定义如下:

{
"compileOnSave": false,
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"mapRoot": "",
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": false,
"outDir": "../dist/",
"rootDir": ".",
"sourceMap": true,
"target": "es5",
"inlineSources": true
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}

最佳答案

要能够使用 module.id,您的项目必须是一个 commonjs 模块,即在 tsconfig 中将 module 属性设置为 commonjs。 json 文件。是这样吗:

{
"compilerOptions": {
"target": "es5",
"module": "commonjs", // <-----
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}

关于javascript - 在 Angular2 应用程序中找不到名称模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37165466/

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