Skip to content
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

Make npm package ES6 module friendly #246

Closed
tidoust opened this issue Feb 17, 2021 · 2 comments
Closed

Make npm package ES6 module friendly #246

tidoust opened this issue Feb 17, 2021 · 2 comments

Comments

@tidoust
Copy link
Member

tidoust commented Feb 17, 2021

The NPM package only contains the index.json file. That file can easily be retrieved with require:

const specs = require("browser-specs");

However, I believe that there is no easy to achieve the same thing in a project that uses import statement (in other words, when the project enables ECMASCript modules). The following does not work:

import specs from "browser-specs";

For that to work, the entry point of the package needs to be a JS file, not a JSON one.

@tidoust
Copy link
Member Author

tidoust commented Feb 18, 2021

Note ongoing proposal in ECMAScript to enable import of JSON modules

@tidoust
Copy link
Member Author

tidoust commented Nov 27, 2023

Closing. Import attributes are still under development and may still change, but the feature is already supported in Node.js and Deno. The following works out of the box with Node.js v20.10.0 or above:

import specs from 'web-specs' with { type: 'json' };

Older versions of Node.js rather use assert:

import specs from 'web-specs' assert { type: 'json' };

@tidoust tidoust closed this as completed Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant