App crash after import from react-pdf
See original GitHub issueBefore you start - checklist
- I followed instructions in documentation written for my React-PDF version
- I have checked if this bug is not already reported
- I have checked if an issue is not listed in Known issues
- If I have a problem with PDF rendering, I checked if my PDF renders properly in Mozilla Firefox -> not a pdf problem
Description
Short description of the bug you encountered.
When I add the line
Just after I create a new app with create-react-app and add with npm react-pdf,
If import from react-pdf like that :
import { Document } from "react-pdf"
My app can’t compile anymore.
Steps to reproduce
Steps to reproduce the behavior:
-
Create a new app with create-react-app
npx create-react-app test-react-pdf
-
Install react-pdf
npm install react-pdf
-
Add in
src/App.js
an import from react-pdfimport { Document } from "react-pdf"
-
Run npm start and it should display something like:
<--- Last few GCs --->
[47073:0x102808000] 31515 ms: Scavenge 1382.5 (1423.4) -> 1381.9 (1423.9) MB, 4.6 / 0.0 ms (average mu = 0.125, current mu = 0.063) allocation failure
[47073:0x102808000] 31519 ms: Scavenge 1382.7 (1423.9) -> 1382.1 (1424.4) MB, 3.3 / 0.0 ms (average mu = 0.125, current mu = 0.063) allocation failure
[47073:0x102808000] 31524 ms: Scavenge 1383.2 (1424.4) -> 1382.6 (1424.9) MB, 3.1 / 0.0 ms (average mu = 0.125, current mu = 0.063) allocation failure
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x1d21277dbe3d]
Security context: 0x2cd62ef9e6e9 <JSObject>
1: SourceMapConsumer_allGeneratedPositionsFor [0x2cd6b4a57591] [/Users/mypcname/Dev/test-react-pdf/node_modules/@babel/core/node_modules/source-map/lib/source-map-consumer.js:~178] [pc=0x1d212805103b](this=0x2cd682a82291 <BasicSourceMapConsumer map = 0x2cd6d22b6131>,aArgs=0x2cd638193081 <Object map = 0x2cd6d22b5529>)
2: /* anonymous */(aka /* a...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x10003d035 node::Abort() [/usr/local/bin/node]
2: 0x10003d23f node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
3: 0x1001b8e15 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
4: 0x100586d72 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
5: 0x100589845 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/bin/node]
6: 0x1005856ef v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
7: 0x1005838c4 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
8: 0x10059015c v8::internal::Heap::AllocateRawWithLigthRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
9: 0x1005901df v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x10055fb24 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
11: 0x1007e7e04 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x1d21277dbe3d
13: 0x1d212805103b
I also create a repo with the problem https://github.com/ditiz/pdf-viewer To use it:
git clone https://github.com/ditiz/pdf-viewer.git
npm install
npm start
Expected behavior
What you expected to happen? Can use react-pdf without crash the app
Additional information
I tried to use more ram with:
react-scripts --max_old_space_size=4096 start
It’s change nothing
If applicable, add screenshots (preferably with browser console open) and files you have an issue with to help explain your problem.
Environment
- Browser (if applicable) [e.g. Chrome 57, Firefox 59]: not used
- React-PDF version [e.g. 3.0.4]: 4.1.0
- React version [e.g. 16.3.0]: 16.12.0
- Webpack version (if applicable) [e.g. 4.16.2]: 4.41.2
Issue Analytics
- State:
- Created 4 years ago
- Reactions:20
- Comments:18 (2 by maintainers)
Top GitHub Comments
I had the same error when I upgrade to react-scripts 3.3.0. Adding the following to the .env.development file got things running:
GENERATE_SOURCEMAP=false
I found that if you import components from
import { Document, Page } from 'react-pdf/dist/entry.webpack';
everything is working fine. This import delegates rendering work to a different thread which apparently fixes issues with memory allocation limit. I hope this helps 😃.