-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package.json type module #10821
Comments
We have evaluated this and decided to wait with adding |
Thanks for the feedback. True esm works, as long as I dont write my package as a module (I think, haven't tried this yet exctensively). I decided to wait for Node 14 as well for now, had some other issues with the experimental API. |
@ahocevar, any chances of reevaluating your decision? 😄 |
@tschaub may want to weigh in here, because he did some more research on the topic a while ago. I'm not opposed to adding this setting, but mostly it needs testing with the bundlers we have examples for (see https://github.com/openlayers/openlayers/#getting-started). In addition, I want to test it with some of my applications where I use OpenLayers with Node and esm. Unfortunately my schedule is quite tight at the moment, so it might be May before I get to it. So if anyone can test and provide reports here, it might speed up the process. |
To bud in here as the one who opened this. I am actually using openlayers in a node |
@ahocevar, how about an alternative, less invasive, solution - publishing the transpiled import { default as ol } from 'ol/ol'; and use everything as in the examples. The only downside is that you won't be able to share code between the server and the client-side. |
Additional downside: you loose tree shacking, no? |
@bkuster, yes, but this is server-side, tree shaking doesn't mean much here |
I think we don't want to publish the legacy build, so we'll rather go the route of testing. I'd say to make this easier for everyone, we'd accept a pull request to make the suggested change in package.json. Then we'll have something to test with https://github.com/openlayers/ol-rollup, https://github.com/openlayers/ol-webpack, https://github.com/openlayers/ol-parcel, https://github.com/openlayers/ol-browserify, and in two yet-to-create repositories, one with node + CommonJS + esm, and one with node modules. |
You want a PR for adding There is a reason why harassment on the workplace is a serious criminal offence, while harassment outside of it usually elicits a smile, except in the very rare cases of a criminally insane person, who cannot comprehend when and why people laugh at him. |
Now do you want |
I won't get around to it today, but my colleagues might. Otherwise I'll open a PR Monday and verify it works with your bundler examples. We've tested it with web-dev-server so far. |
I decided to resurrect an old branch that converted our package to You can There is still work to do to convert the test utilities (and probably doc things). I'll migrate #12241 out of draft state when that is done. |
@tschaub thanks for the update and the work you've already put in. Should have some time to check it out next week. |
Anyone know what the last version of openlayers that used commonjs ? So, if anyone knows how far back I need to go to get the last "proper" commonjs version? I got as far back as 6.4.3 which states it's |
OpenLayers never published CommonJS modules. It sounds like your code runs in Node, not in a browser. If this is the case, I'd suggest using the latest ol version and - if you haven't already - upgrading to Node >= 14, or using https://npmjs.com/package/esm for older Node versions. Then ES modules should work. |
We have the latest node. But our project codebase compiles down from typescript to commonjs.
in typescript I write
and it gets turned into
in the generated files. |
Looks like you're using |
Yep, and a that point, node cannot run the code unless I make package.json a |
Without seeing more of your project setup, I cannot provide specific advice. But I have successfully used OpenLayer s in a CommonJS setup both natively with Node 16 and with esm in previous Node versions. |
I am having similar issues with SvelteKit, I have changed all
Should this be reported to |
In case anybody comes across this, see #13114 (comment) for a working example using SvelteKit and OpenLayers. The GeoTIFF source cannot (currently) be imported in Node, but others can. |
Describe the bug
Using the new (but still exprimental) node esm loading mechanism does not work with the current version of ol's package.json.
To Reproduce
npm i ol
import { createXYZ } from 'ol/tilegrid.js';
node --experimental-modules index.js
gives the following error:Expected behavior
The module should be imported.
Fix
Add
"type": "module"
to the package.jsonThe text was updated successfully, but these errors were encountered: