-
-
Notifications
You must be signed in to change notification settings - Fork 894
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
Webpack entry point doesn't work with create-react-app on newest react-scripts 5.0.0 #912
Comments
I am not using react-pdf, but the underlying pdfjs library and I ran into the same issue, when switching to react-scripts@5.0.0 . |
See also also #facebook/create-react-app/issues/8096 and #react-pdf/issues/498#issuecomment-566948710 |
It seems that it is related to loading the webworker itself, as it is too big and it fails creating the sourcemap. I don't really like the option of disabling the sourcemap, but it seems that it is the only option at the moment |
I also do not like it. I have also found older solutions, where transpiling using babbel for the worker was deactivated. But I found no way how to do this without ejecting create react. |
I'm also running in to this problem using The only way I found to get around it is setting Thanks for an otherwise awesome library! |
The problem lie in the last update of react-scripts. It update webpack in version > 5, and in that version webpack don't polifyll by default nodejs core modules, used by react pdf. React team is working on it, and there is a good thread on it here : facebook/create-react-app#11756 And the current way to fix the issue : facebook/create-react-app#11756 (comment) and under |
@lorenzoalfieri why would you say that it has to do with the polifyll? Which specific polifyll is it missing to be able to load the worker? I can see that for the |
I agree this doesn't seem to be related to the change in how webpack 5 handles polifylls. I found this SO that seems relevant. Changing my script to use For now the only option that seems to work is using |
@albireox: I also tried this with no luck. The only thing, which could work was an idea, which suggested excluding the webworker file from transpiling, but either required ejecting react or was really complicated. |
Looks like this is caused by default create-react-app Webpack configuration parsing node_modules using Babel by default. React-PDF, more specifically its direct dependency pdfjs-dist, is particularly heavy, causing the out of memory error. Related: facebook/create-react-app#8096 |
So, I was playing around with the source code and I found a potential solution. The import of the webworker could be modified to:
adding Probably, the CRA is adding some preLoaders or postLoaders that generates the source map |
Nice find @franjaviersans! Technically, This led me to the following section: https://webpack.js.org/guides/asset-modules/#url-assets It appears like what we could do here for Webpack 5 would be very similar if not identical to our new Parcel 2 loader: react-pdf/src/entry.parcel2.js Line 11 in 95cd4ef
So in f213e54 that's exactly what I did. I just tested it though and it doesn't seem to fix the underlying issue though - CRA still does something that causes out of memory bug. |
Yes, I was also considering using I did try loading with:
But we still get the memory issue |
Official recommendationREADME was updated to include Create React App 5 instructions. Please have a read. https://github.com/wojtekmaj/react-pdf#create-react-app A full working sample repo has been also added in #923: https://github.com/wojtekmaj/react-pdf/tree/main/sample/create-react-app-5 |
Before you start - checklist
Description
I'm trying to use
esm/entry.webpack
to enable the worker withcreate-react-app 5.0.0
and the application is not being able to build due to heap allocation problems.Steps to reproduce
create-react-app
with create-react-app ensuring that it usesreact-scripts 5.0.0
react-pdf 5.6.0
Expected behavior
Application builds and is able to run
Actual behavior
Fails to build with the following error:
Additional information
Here is the
package.json
content:Here is a small code used:
Environment
The text was updated successfully, but these errors were encountered: