运行时错误:无法find模块“leaflet.awesome-markers”离子3
我正在使用Leaflet将Font Awesome标记添加到Ionic 3应用程序,该Leaflet可以成功显示Leaflet的内置标记,但是当我尝试导入leaflet.awesome标记模块时, ionic serve
报告运行时错误,说明找不到模块leaflet.awesome-markers
。
我遵循的一个build议是删除node_modules
目录,让npm重新安装所有东西。 这并没有改变结果。
ionic info
输出:
cli packages: (/home/jett/git/mobiLoc/node_modules) @ionic/cli-plugin-cordova : 1.6.2 @ionic/cli-plugin-ionic-angular : 1.4.1 @ionic/cli-utils : 1.7.0 ionic (Ionic CLI) : 3.7.0
全球套餐:
Cordova CLI : 7.0.1
本地套餐:
@ionic/app-scripts : 1.3.7 Cordova Platforms : android 6.2.3 ios 4.4.0 Ionic Framework : ionic-angular 3.2.1
系统:
Android SDK Tools : 26.0.2 Node : v7.10.0 OS : Linux 4.4 npm : 4.2.0
来自package.json
:
"@types/leaflet": "^1.2.0", "@types/leaflet.awesome-markers": "^2.0.4", "leaflet": "^1.2.0", "leaflet.awesome-markers": "^2.0.4", "typescript": "2.3.4"
相关代码:
import * as L from "leaflet"; import "leaflet.awesome-markers"; private issueIcon: L.AwesomeMarkers.Icon; this.issueIcon = L.AwesomeMarkers.icon({ icon: 'heart-broken', /* Heart with a crack */ markerColor: 'red', prefix: "fa" });
我是新来的1)types脚本和2)debugging依赖于types定义的第三方模块的导入。 然而,这似乎不是解决types的问题 – 我的IDE能够识别leaflet.awesome-markers
文件中定义的types。 没有编译/ transpile错误/警告。
由于没有编译时问题,这似乎排除了该模块上的权限问题,但我已经检查了所有node_modules都安装在本地项目中,并且在整个目录中具有相同的权限。
对其他debugging方法感兴趣。
我不完全了解npm
或我的IDE如何解决导入问题,但是我偶然发现了一个命令,提供了更多关于解决导入问题的详细信息。 为了获得额外的细节,我使用了
npm run build
代替
ionic serve
npm run build
命令提供了parsing该行时尝试使用的各种path和扩展的详细信息:
import "leaflet.awesome-markers";
我发现构build能够解决这个文件,一旦我改变import
语句的实际.js文件的位置:
import "leaflet.awesome-markers/dist/leaflet.awesome-markers";