Geo*_*tan 11 javascript node.js typescript angular
我通过添加此属性更改了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.
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
更新:
如果我更改为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.
Run Code Online (Sandbox Code Playgroud)
正如我所说,现在正在运行,但 VSCode 有问题。
Pok*_*Art 86
"allowSyntheticDefaultImports": true
该标志解决了问题,但应将其添加到tsconfig.json 的compilerOptions部分
如果您在尝试将 localforage 导入 angular 9 时遇到此错误,我使用了这个(Angular 9.1.12,Typescript 3.9.6):
npm 安装本地草料
// tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
},
"esModuleInterop": true, <----------------------------add this
"allowSyntheticDefaultImports": true <----------------------------and this
}
Run Code Online (Sandbox Code Playgroud)
// 任何组件或服务
import * as localforage from 'localforage';
constructor() {
localforage.setItem('localforage', 'localforage value');
setTimeout(() => {
localforage.getItem('localforage').then((e) => {
console.log(e);
});
}, 5000);
setTimeout( async () => {
const RES = await localforage.getItem('localforage');
console.log('RES', RES);
}, 10000);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
24213 次 |
最近记录: |