无法在 Angular 9 中进行默认导入 [英] Can't do a default import in Angular 9
本文介绍了无法在 Angular 9 中进行默认导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过添加此属性更改了 tsconfig.json
I changed tsconfig.json by adding this properties
"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 中不能正常工作,并且错误是
If I change with import ms from "ms"
, then it works fine with the compiler but not with VSCode linter and the error is
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 有问题.
As I said now is working but VSCode have a problem.
推荐答案
问题是包怎么声明导出的,还是可以用默认的import导入:
The problem is how the package declared the export, you can still import using the default import:
import ms from "ms";
这篇关于无法在 Angular 9 中进行默认导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文