【发布时间】:2020-07-11 03:17:22
【问题描述】:
我通过添加此属性更改了 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 有问题。
【问题讨论】:
-
您是否尝试过使用默认导出?也许this can help.
-
ms 是一个 npm 包
-
尝试像这样导入:
import ms from "ms"; -
谢谢 Lucas,它与 Angular 编译器一起工作,但 VSCode 仍然不喜欢它
-
如果取出tsconfig.json属性
"allowSyntheticDefaultImports": true,,可以用*语法导入吗?
标签: javascript node.js angular typescript