【问题标题】:Visual studio 2019 Cannot use imports, exports, or module augmentations when '--module' is 'none'当“--module”为“无”时,Visual Studio 2019 无法使用导入、导出或模块扩充
【发布时间】:2020-11-17 20:13:18
【问题描述】:

在我将项目从 Angular 9 升级到 Angular 10 后,该项目显示了许多我无法解决的错误,如下所示

(TS) 找不到模块“@angular/core”。
(TS) 找不到模块“@angular/forms”。
(TS) 当“--module”为“none”时,不能使用导入、导出或模块扩充。
(TS) 对装饰器的实验性支持是一项可能在未来版本中更改的功能。设置“experimentalDecorators”选项以删除此警告。
TS6053 文件 'ClientApp/node_modules/-/dist/index.d.ts' 未找到

错误消息仅在 Visual Studio 2019 中显示。当我在 Visual Studio 代码中尝试该应用程序时,它工作正常。

我尝试了很多解决方案,例如添加
<TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators> <TypeScriptEmitDecoratorMetadata>True</TypeScriptEmitDecoratorMetadata>

或添加
"baseUrl": "src"
到 tsconfig.json

他们都没有工作。有没有人遇到同样的问题?

【问题讨论】:

    标签: typescript .net-core visual-studio-2019 angular10


    【解决方案1】:

    这是 Visual Studio 2019 无法处理新的“解决方案式”tsconfig 文件的问题。

    您可以阅读 Angular 10 CLI 升级带来的变化:

    https://angular.io/guide/migration-solution-style-tsconfig

    为了在 Visual Studio 2019 中正常工作,最简单的解决方法是更改​​您的 tsconfig.json 文件,使其在没有“解决方案样式”配置模式的情况下工作,如下所示:

    {
      "extends": "./tsconfig.app.json"
      //"files": [],
      //"references": [
      //  {
      //    "path": "./tsconfig.app.json"
      //  },
      //  {
      //    "path": "./tsconfig.spec.json"
      //  }
      //]
    }
    

    这是一个已知问题,Visual Studio 团队目前正在努力解决此问题,以支持这种新型 TypeScript 配置文件。

    【讨论】:

    • 非常感谢。这暂时解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 2020-05-02
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    相关资源
    最近更新 更多