question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

package.json type module

See original GitHub issue

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

  1. npm i ol
  2. in index.js import { createXYZ } from 'ol/tilegrid.js';
  3. node --experimental-modules index.js gives the following error:

Cannot use import statement outside a module

Expected behavior The module should be imported.

Fix Add "type": "module" to the package.json

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:22 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
tschaubcommented, Apr 26, 2021

I decided to resurrect an old branch that converted our package to "type": "module" for the whole repo - not just for the published package. This wasn’t working that well with Node < 14 (when I last tried it) but is working better now.

You can npm install ol@module to try it out. Here is a draft PR for the ol-parcel project: openlayers/ol-parcel#1.

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.

1reaction
ahocevarcommented, Mar 19, 2020

We have evaluated this and decided to wait with adding "type": "module" until ES modules are stable in Node (perhaps Node 14). In the meantime, you can use esm to make OpenLayers work in a Node environment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modules: Packages | Node.js v19.3.0 Documentation
Within a package, the package.json "type" field defines how Node.js should interpret .js files. If a package.json file does ...
Read more >
Why is 'type: module' in package.json file? - Stack Overflow
When you have "type": "module" in the package.json file, your source code should use import syntax. When you do not have, you should...
Read more >
To load an ES module, set "type" - "module" in JavaScript
The "To load an ES module, set "type": "module" in package.json" error occurs when using the ES6 Modules syntax in a Node.js application...
Read more >
Documentation - ECMAScript Modules in Node.js - TypeScript
Node.js supports a new setting in package.json called type . "type" can be set to either "module" or "commonjs" . ... This setting...
Read more >
package.json - npm Docs
Don't use the same name as a core Node module. Don't put "js" or "node" in the name. It's assumed that it's js,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found