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

publish es6 modules to npm #10317

Closed
robrez opened this issue Nov 29, 2018 · 15 comments · Fixed by #17055
Closed

publish es6 modules to npm #10317

robrez opened this issue Nov 29, 2018 · 15 comments · Fixed by #17055
Labels

Comments

@robrez
Copy link

robrez commented Nov 29, 2018

I was looking to use pdf.js today via something like import {pdfjs} from pdfjs-dist/pdf.js and learned that all that is available is a require module.

Would it be possible to add es6 modules somewhere on npm?

@bennypowers
Copy link

In an ideal world, src should be refactored as standard modules. If CJS is still needed, it could be automatically built (say, in a cjs directory) using rollup or other similar tools, or better yet - left up to the user to generate (node users could easily use the esm module to enable es module syntax in node apps). That would allow library users to choose if, when, and how to bundle or transpile.

If there's interest, I'd be happy to provide a PR.

@robrez
Copy link
Author

robrez commented Dec 12, 2018

As an interim workaround, we've published this:

https://github.com/bundled-es-modules/pdfjs-dist
https://www.npmjs.com/package/@bundled-es-modules/pdfjs-dist

@amundo
Copy link

amundo commented Aug 8, 2019

Is this the bundled-es-modules/pdfjs-dist repo still relevant or has module functionality been rolled into this main distribution? There seem to be “components” in this repo.

@daKmoR
Copy link

daKmoR commented Aug 21, 2019

the published pdfjs-dist still seems to not have es modules?

or is there another distribution somewhere?

@xiaoxiangmoe
Copy link

xiaoxiangmoe commented Aug 7, 2020

@timvandermeij any update on this?

node_modules/ng2-pdf-viewer/__ivy_ngcc__/fesm2015/ng2-pdf-viewer.js depends on 'pdfjs-dist/build/pdf'. CommonJS or AMD dependencies can cause optimization bailouts.

@rondonjon
Copy link

@bennypowers:

If there's interest, I'd be happy to provide a PR.

That would be very helpful.

@janetlee
Copy link

Hi! Commenting to give this a bump. I would love this to be tree-shakeable since I do not actually need pdfjs-dist. I have a broken TS config (Which I am trying to fix) but tree-shaking would eliminate this error being thrown in the first place.
wojtekmaj/react-pdf#280 (comment)

@nischi

This comment has been minimized.

@zenflow
Copy link

zenflow commented Apr 28, 2022

This is a big issue as the JS package ecosystem migrates from CommonJS to ESM. The migration has progressed a lot since this issue was opened in 2018, and ESM is now very much standard, and nowhere near bleeding-edge (especially on frontend, as opposed to on nodejs which is another story).

Webpack can still handle this, but next-gen bundlers like Vite cannot.

@Snuffleupagus Any plan to publish ES Modules to catch up with the ecosystem?

@zenflow
Copy link

zenflow commented Apr 28, 2022

#10317 (comment):

the published pdfjs-dist still seems to not have es modules?

https://unpkg.com/browse/[email protected]/build/pdf.js => UMD
https://unpkg.com/browse/[email protected]/lib/pdf.js => commonjs
or is there another distribution somewhere?

https://github.com/mozilla/pdf.js/blob/master/src/pdf.js => ES modules

This project is developed with ES modules, but the src/ dir just isn't published in the package on NPM.

Seems like this would be an easy fix, no?

@Snuffleupagus
Copy link
Collaborator

Any plan to publish ES Modules to catch up with the ecosystem?

Please keep in mind that the primary focus of development for this library is the Firefox PDF Viewer.

For the general PDF.js library, we've been doing various work (over the years) to clean-up and simplify things in order to reduce the number of builds that we have to maintain/support. Hence why we provide both browser and Node.js support in the same builds in e.g. pdfjs-dist, and thus it's not currently planned to add any "new" builds.

This project is developed with ES modules, but the src/ dir just isn't published in the package on NPM.

And neither should it be, since the only thing that we officially support is the functionality accessed via https://github.com/mozilla/pdf.js/blob/master/src/pdf.js respectively https://github.com/mozilla/pdf.js/blob/master/web/pdf_viewer.component.js (once those files are built and and published in pdfjs-dist).

Please keep in mind that using the "raw" src/-files directly has never be officially recommended nor supported. (Hence the only thing that may, some day in the future, become supported are ESM-versions of the files in e.g. the https://github.com/mozilla/pdfjs-dist/tree/master/build and https://github.com/mozilla/pdfjs-dist/tree/master/web folders.)

Seems like this would be an easy fix, no?

Not really, since as mentioned above we don't want to add even more builds and we also want to support both browsers and Node.js environments with the same builds.

@justinfagnani
Copy link

Node package exports would allow you to publish plain, unbundled modules but only allow importing specific entry points.

Node has also supported modules for the last 7 major and 4 LTS versions, so you could still keep one build for both (modulo using environment specific API like DOM and process.env).

@arcs-
Copy link

arcs- commented Jan 9, 2023

This would be a great addition to have in 2023

@quantuminformation

This comment was marked as off-topic.

@ODAncona

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.