react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

add module entrypoint to support js cdn

Open triggertoo opened this issue 7 years ago • 10 comments

pika.dev currently complains about the missing module entrypoint. It would be great to have it to support the javascript cdn.

triggertoo avatar Jul 08 '19 09:07 triggertoo

Hmmm. I wonder how to configure it properly. React-PDF currently ships as CommonJS code in multiple files. So essentially we would need to have /dist/umd and /dist/esm folders, with two different versions of the code, right?

wojtekmaj avatar Jul 08 '19 14:07 wojtekmaj

I have the same need

mraiguo avatar Jul 09 '19 06:07 mraiguo

Hmmm. I wonder how to configure it properly. React-PDF currently ships as CommonJS code in multiple files. So essentially we would need to have /dist/umd and /dist/esm folders, with two different versions of the code, right?

Generating a separate ES2015 build seems like the right approach to me as mentioned on https://github.com/rollup/rollup/wiki/pkg.module

triggertoo avatar Jul 10 '19 07:07 triggertoo

I published [email protected]. Could you kindly test if that setup works correctly?

wojtekmaj avatar Jul 27 '19 13:07 wojtekmaj

I attempted to install dependencies for a package that relies on react-pdf using [email protected] and it looks like during the build step it borked.

$yarn
yarn install v1.17.3
[1/5] 🔍  Validating package.json...
[2/5] 🔍  Resolving packages...
Couldn't find any versions for "react-pdf" that matches "[email protected]"
? Please choose a version of "react-pdf" from this list: 4.2.0-beta
[3/5] 🚚  Fetching packages...
[4/5] 🔗  Linking dependencies...
warning "react-pdf > [email protected]" has unmet peer dependency "webpack@^3.0.0 || ^4.0.0-alpha.0 || ^4.0.0".
warning "react-pdf > pdfjs-dist > [email protected]" has unmet peer dependency "webpack@^3.0.0 || ^4.0.0-alpha.0 || ^4.0.0".
[5/5] 🔨  Building fresh packages...
success Saved lockfile.
$ yarn run build
yarn run v1.17.3
$ rollup -c

src/index.js → dist/index.js, dist/index.es.js...
Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade caniuse-lite browserslist`
preferring built-in module 'url' over local alternative at '/Users/timyager/code/react-multimedia-lightbox/node_modules/url/url.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
preferring built-in module 'url' over local alternative at '/Users/timyager/code/react-multimedia-lightbox/node_modules/url/url.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
preferring built-in module 'url' over local alternative at '/Users/timyager/code/react-multimedia-lightbox/node_modules/url/url.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
preferring built-in module 'url' over local alternative at '/Users/timyager/code/react-multimedia-lightbox/node_modules/url/url.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
preferring built-in module 'url' over local alternative at '/Users/timyager/code/react-multimedia-lightbox/node_modules/url/url.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning
(!) Unresolved dependencies
https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency
url (imported by node_modules/pdfjs-dist/build/pdf.js, commonjs-external:url)
zlib (imported by node_modules/pdfjs-dist/build/pdf.js, commonjs-external:zlib)
http (imported by node_modules/pdfjs-dist/build/pdf.js, commonjs-external:http)
fs (imported by node_modules/pdfjs-dist/build/pdf.js, commonjs-external:fs)
https (imported by node_modules/pdfjs-dist/build/pdf.js, commonjs-external:https)
[!] Error: 'PDFDataRangeTransport' is not exported by node_modules/pdfjs-dist/build/pdf.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
node_modules/react-pdf/dist/esm/Document.js (23:16)
21: import makeCancellable from 'make-cancellable-promise';
22: import mergeClassNames from 'merge-class-names';
23: import pdfjs, { PDFDataRangeTransport } from 'pdfjs-dist';
                    ^
24: import DocumentContext from './DocumentContext';
25: import Message from './Message';

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

creativetim avatar Oct 25 '19 20:10 creativetim

I'm experiencing the same error as above after installing 5.0.0-beta... Any progress made on this? I'm currently blocked by this issue.

adepatie avatar Nov 19 '19 16:11 adepatie

I'm confused, first time I see this. PDFDataRangeTransport is definitely exported by pdfjs-dist. However, pdfjs-dist is CommonJS, so maybe that's a problem here. Check if the code starts working if you change this in node_modules/react-pdf/dist/esm/Document.js:

-import pdfjs, { PDFDataRangeTransport } from 'pdfjs-dist';
+import pdfjs from 'pdfjs-dist';
+const { PDFDataRangeTransport } = pdfjs;

If that makes the situation better, I'll try and make a bugfix for that.

wojtekmaj avatar Nov 21 '19 16:11 wojtekmaj

Closing as the feature landed in #429; please use #495 to share your experience with v5.0.0-beta. Please let me know if the workaround above worked.

wojtekmaj avatar Dec 07 '19 20:12 wojtekmaj

@wojtekmaj could you please create a new tag with this fix?

-import pdfjs, { PDFDataRangeTransport } from 'pdfjs-dist';
+import pdfjs from 'pdfjs-dist';
+const { PDFDataRangeTransport } = pdfjs;

It's holding us from compiling our packages.

Thank you for the package

64n35h4 avatar Jun 24 '20 13:06 64n35h4

@NordRagnarok Fixed in 40b26f7, but we're still in looong testing phase of the next release :(

wojtekmaj avatar Jun 25 '20 13:06 wojtekmaj