javascript - 无法在 Angular 9 中进行默认导入

标签 javascript node.js angular typescript

我改了 tsconfig.json 通过添加此属性
"esModuleInterop": true, "allowSyntheticDefaultImports": true,
为了能够导入 npm 包 import * as ms from "ms";
但我仍然收到此错误

This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

我错过了什么?

更新:

如果我更改为 import ms from "ms" ,然后它可以在编译器上正常工作,但不能在 VSCode linter 上正常工作,错误是
 can only be default-imported using the 'allowSyntheticDefaultImports' flagts(1259)
index.d.ts(25, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

正如我所说,现在可以工作,但 VSCode 有问题。

最佳答案

"allowSyntheticDefaultImports": true此标志解决了问题,但应将其添加到 编译器选项 tsconfig.json 部分

关于javascript - 无法在 Angular 9 中进行默认导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60935889/

相关文章:

node.js - Sails mongo 重新连接

angular - 如何在angular 2 ag-grid中的两行ag-grid之间添加空间

javascript - 如何交换json

macos - node-expat 导致 npm 因 Node 安装 SOAP 而失败

javascript - 如何使用javascript获取body标签的值?

javascript - 如何使用 React Native Facebook SDK GraphRequest 获得高质量的头像?

javascript - 不使用 Flexbox 的响应式 div

json - 无法让 xlsx 到 JSON 转换器在 Node/Express 中正常工作

javascript - 解决错误错误 : "[object Object]" in angular

javascript - 如何确保树形图单元格中的文本不会溢出?