我改了 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/