【问题标题】:when creating new module throw Experimental support for decorators error创建新模块时抛出对装饰器的实验性支持错误
【发布时间】:2020-11-04 23:33:20
【问题描述】:

我正在尝试在 Angular 项目中生成新模块

ng g module core/employee-applicant --routing=true

并且生成的新模块抛出异常

对装饰器的实验性支持是一项受制于 在将来的版本中更改。设置 'experimentalDecorators' 选项 你的 'tsconfig' 或 'jsconfig' 来删除这个警告。

在其他模块中它不会产生该错误。

出现错误的新模块

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { EmployeeApplicantRoutingModule } from './employee-applicant-routing.module';


@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    EmployeeApplicantRoutingModule
  ]
})
export class --> EmployeeApplicantModule (the error on visual studio code red under line){ }

不弹出该错误的旧模块

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

import { AuthRoutingModule } from './auth-routing.module';
import { LoginComponent } from './login/login.component';
import { MaterialModule } from 'src/app/shared/modules/material.module';
import { PipesModule } from 'src/app/pipes-module';


@NgModule({
  declarations: [
    LoginComponent
  ],
  imports: [
    CommonModule,
    AuthRoutingModule,
    FormsModule,
    ReactiveFormsModule,
    MaterialModule,
    PipesModule,
  ]
})
export class AuthModule { }

与使用该新模块生成的路由模块相同。

对于experimentalDecorators,我将它添加到我项目的每个 tsconfig 文件中

tsconfig.app.json

tsconfig.spec.json

tsconfig.json

tsconfig.base.json

如果有人能告诉我这些文件有什么区别

当我尝试将它导入到 app.module 时,它并没有显示出来,我认为这是因为那个错误

【问题讨论】:

    标签: angular typescript angular10


    【解决方案1】:

    我的 tsconfig.json 中有以下内容,它工作正常

       {
        "compilerOptions": {
        "target": "ES5",
         "experimentalDecorators": true
          }
        }
    

    【讨论】:

      【解决方案2】:

      伙计们,这似乎是 Visual Studio 代码中的一个错误

      我通过写入整个路径将其硬导入其他模块然后错误消失

      至少这为我解决了我不知道如何......

      【讨论】:

        猜你喜欢
        • 2020-11-07
        • 1970-01-01
        • 2020-11-08
        • 2019-01-25
        • 2017-02-22
        • 1970-01-01
        • 2019-07-11
        • 2017-11-06
        • 2021-10-03
        相关资源
        最近更新 更多