openlayers: Cannot find module 'ol/proj' (but all the others are OK)
Edit: I have solved the issue replacing it like this =>
//import proj from 'ol/proj'; // ! ERROR: Cannot find module 'ol/proj'.
const proj = (<any>require('ol/proj')).default;
I suspect that the @types/ol has an error regarding the type declaration of 'ol/proj', which is why import wouldn’t work.
It is imported as shown in the documentation. All the other imports work fine.
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
This is my package.json (notice that I am using Typescript):
{
"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
}
}
These are the contents of .\node_modules\ol. The file proj.js is present there.
Although there is also a folder \proj that I suspect could be a problem. If I write import proj4 from 'ol/proj/proj4'; (<= .\ol\proj\proj4.js) it works fine. But I need 'ol/proj' instead of that.
Update: the module resolution seems to be coherent with the standards. The subfolder should not be an issue.
.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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 15 (8 by maintainers)
Or use named import.
import * as proj from 'ol/proj';