我正在使用第三方库"openlayers"。
失败的导入是'ol/proj'
。它是导入的as shown in the documentation。所有other imports都可以正常工作。
import proj from 'ol/proj'; // ! ERROR: Cannot find module 'ol/proj'.
import ol from 'ol'; // OK
import 'ol/ol.css'; // OK
import Map from 'ol/map'; // OK
import View from 'ol/view'; // OK
import TileLayer from 'ol/layer/tile'; // OK
import XYZSource from 'ol/source/xyz'; // OK
这是我的package.json
:
{
"name": "MyProject",
"private": true,
"version": "0.0.0",
"devDependencies": {
"@types/webpack-env": "^1.13.0",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "^3.0.0",
"bootstrap": "^3.3.6",
"css-loader": "^0.25.0",
"event-source-polyfill": "^0.0.7",
"extract-text-webpack-plugin": "^2.0.0-rc",
"file-loader": "^0.9.0",
"isomorphic-fetch": "^2.2.1",
"jquery": "^3.1.1",
"style-loader": "^0.13.1",
"typescript": "^2.2.1",
"url-loader": "^0.5.7",
"vue": "^2.2.2",
"vue-loader": "^11.1.4",
"vue-property-decorator": "^5.0.1",
"vue-router": "^2.3.0",
"vue-template-compiler": "^2.2.2",
"webpack": "^2.2.0",
"webpack-hot-middleware": "^2.12.2",
"ol": "^4.6.5", <============= this library
"@types/ol": "^4.6.1", <====== typescript types
}
}
这些是.\node_modules\ol
的内容。文件proj.js
出现在那里。
虽然还有一个文件夹\proj
我怀疑可能是个问题。如果我写import proj4 from 'ol/proj/proj4';
(&lt; = .\ol\proj\proj4.js
),它可以正常工作。但我需要'ol/proj'
而不是那个。
更新:模块解析seems to be coherent with the standards。子文件夹应该不是问题。
.eslintrc
array.js
assertionerror.js
asserts.js
attribution.js
canvasmap.js
centerconstraint.js
collection.js
collectioneventtype.js
color.js
color.jsdoc
colorlike.js
colorlike.jsdoc
<DIR> control
control.js
coordinate.js
coordinate.jsdoc
css.js
deviceorientation.js
disposable.js
dom.js
easing.js
easing.jsdoc
<DIR> events
events.js
<DIR> extent
extent.js
extent.jsdoc
feature.js
featureloader.js
featureloader.jsdoc
<DIR> format
functions.js
geolocation.js
geolocationproperty.js
<DIR> geom
graticule.js
has.js
has.jsdoc
image.js
imagebase.js
imagecanvas.js
imagestate.js
imagetile.js
index.js
<DIR> interaction
interaction.js
kinetic.js
<DIR> layer
layertype.js
loadingstrategy.js
loadingstrategy.jsdoc
map.js
mapbrowserevent.js
mapbrowsereventhandler.js
mapbrowsereventtype.js
mapbrowserpointerevent.js
mapevent.js
mapeventtype.js
mapproperty.js
math.js
net.js
obj.js
object.js
objecteventtype.js
observable.js
ol.css
overlay.js
overlaypositioning.js
package.json
pluggablemap.js
plugins.js
plugintype.js
<DIR> pointer
<DIR> proj <========= is this a problem?
proj.js <============ OK
readme.md
<DIR> render
render.js
render.jsdoc
<DIR> renderer
<DIR> reproj
reproj.js
resolutionconstraint.js
rotationconstraint.js
size.js
<DIR> source
source.jsdoc
sphere.js
string.js
<DIR> structs
<DIR> style
style.js
tile.js
tilecache.js
tilecoord.js
<DIR> tilegrid
tilegrid.js
tilequeue.js
tilerange.js
tilestate.js
tileurlfunction.js
transform.js
uri.js
<DIR> vec
vectorimagetile.js
vectortile.js
view.js
viewhint.js
viewproperty.js
<DIR> webgl
webgl.js
xml.js