纯JavaScript项目Eclipse中导入geoplugin提示找不到模块声明文件如何解决
解决Eclipse中
geoplugin模块找不到声明文件的错误 方法1:自定义类型声明文件
在项目根目录创建typings/geoplugin/index.d.ts文件(无typings文件夹则新建),写入:
declare module 'geoplugin' { export function getGeo(): any; // 若需使用该模块的其他方法,可在此补充声明 }
接着在项目根目录新建tsconfig.json(已有则直接修改),添加类型目录配置:
{ "compilerOptions": { "typeRoots": ["./node_modules/@types", "./typings"], "allowJs": true } }
方法2:关闭Eclipse的JS类型检查
- 打开Eclipse偏好设置(Preferences)
- 进入
JavaScript > Language Service路径 - 取消勾选
Enable TypeScript type checking for JavaScript files选项 - 应用设置并重启Eclipse
方法3:改用CommonJS导入方式
将原ES模块导入代码替换为:
const { getGeo } = require('geoplugin');
内容的提问来源于stack exchange,提问作者Nelson Teixeira
相关产品推荐
相关产品推荐

