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

Consider exporting the library as native ES module #65

Open
TomasHubelbauer opened this issue Dec 26, 2018 · 3 comments
Open

Consider exporting the library as native ES module #65

TomasHubelbauer opened this issue Dec 26, 2018 · 3 comments

Comments

@TomasHubelbauer
Copy link
Contributor

Hello, I'd like to request that you add support for importing this library using native ES modules, like so:

import qrcode from 'https://unpkg.com/qrcode-generator/qrcode.js';

I would benefit from this when experimenting with QR codes locally, without a build process.

I would have created a pull request, but I am not sure how to feature detect and export the library. Theoretically all you need to do is to add export default { ... }, but in browsers where ES native modules are not supported yet, this would have caused an error to be thrown. At the same time, export cannot be stated conditionally, so feature detection for native ES modules and then export doesn't seem to be possible.

I know you are not using a build process, so I am not going to suggest you create two variants, one with ES module support and one without, because this is not a pressing issue at all (can always just use script and find what I need on window.qrcode), but I am interested if you have any thoughts on how this could be achieved without introducing a build process.

@fictioner
Copy link

请问作者解决了吗

@PhiLhoSoft
Copy link

We also have this need, because we use the library in our Angular project, via the NPM release, and we get this warning:

Warning: C:<path to project>\src\app\shared\view\qrcode.service.ts depends on 'qrcode-generator'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

There is a qrcode-generator-es6 package on NPM, but it seems to be a fork, made 3 years ago, on an older version of the library (not even sure it is about this library, actually! but it kept your project blurb, even if it doesn't make sense).

Would you consider to make an ES6 module release, please?
Anyway, many thanks for your great library.

@GabrielDelepine
Copy link

Hi

This library is hard to use in an ESM project using Typescript >= 4.7 due to the CommonJS implementation.

I could open a PR to bring ESM support but I'd like to know first if the repo's maintainer is willing to merge it or not. Please let me know

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

4 participants