我的.tsx文件中包含以下代码:
import L from 'leaflet';
import icon from 'leaflet/dist/images/marker-icon.png';
import iconShadow from 'leaflet/dist/images/marker-shadow.png';
而Typescript抱怨第二行和第三行。不仅是linter,还是TS编译器本身。
特别是linter说:“它找不到模块'blabla / icon.png'或其相应的类型声明。但是,导入L是可以的。
任何人都知道为什么会这样以及如何解决这个问题?
我的tsconfig文件如下所示:
{
"compilerOptions": {
"outDir": "./dist/", // path to output directory
"sourceMap": true, // allow sourcemap support
"strictNullChecks": true, // enable strict null checks as a best practice
"module": "esnext", // specify module code generation
"jsx": "react", // use typescript to transpile jsx to js
"target": "es5", // specify ECMAScript target version
"allowJs": true, // allow a partial TypeScript and JavaScript codebase
"baseUrl": ".",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"paths": {
}
},
"include" : ["src"],
"exclude": ["node_modules", "dist", "config", ".vscode"]
}
先感谢您。
我通过创建具有以下内容的index.d.ts文件解决了此问题:
declare module '*.png';
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句