【发布时间】:2019-07-09 11:33:21
【问题描述】:
错误:
src/app/app.component.ts:4:12 - 错误 TS2591:找不到名称 '模块'。您需要为节点安装类型定义吗?尝试
npm i @types/node,然后将node添加到 tsconfig 中的 types 字段。4 moduleId:module.id,
当我尝试运行“ng build”以编译我的 Angular 文件时,每次出现“module”var 使用时都会出错。我确定模块在那里,我可以在 node_modules 文件夹中看到它,也可以 ctrl+单击它,然后打开带有模块 var 的文件。
我尝试删除整个 node_modules 目录并重新安装。
我没有动过我的 tsconfig.json,因为我只是在学习到目前为止,但这里是:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
这里是 ts 组件中的使用示例:
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app',
templateUrl: 'app.component.html'
})
export class AppComponent { }
也许这与我的项目结构有关,因为我不太确定要使用什么项目结构。我正在尝试构建 spring + angular 应用程序,具有以下结构:
Angular 应用的结构应该没问题,因为它是由 ng new 命令生成的
angular.json 中的输出路径设置为“outputPath”:“../public”,应该在资源目录中。
请问你有什么问题吗?
【问题讨论】:
标签: angular typescript npm