question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

App crash after import from react-pdf

See original GitHub issue

Before 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-pdf import { 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:closed
  • Created 4 years ago
  • Reactions:20
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

53reactions
brentmitchcommented, Dec 16, 2019

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

15reactions
Raysharrcommented, Dec 28, 2019

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 😃.

Read more comments on GitHub >

github_iconTop Results From Across the Web

My React Native App Crash After Update Target Sdk Version 31
My React Native App crashes after update target Sdk version and compileSdkVersion 31. It was working version 30. Google play forced us this ......
Read more >
react-pdf | Yarn - Package Manager
React -PDF. Display PDFs in your React app as easily as if they were images. Lost? This package is used to display existing...
Read more >
Crashes - Android Developers
An app that is written using machine code or C++ crashes if there's an unhandled signal, such as SIGSEGV , during its execution....
Read more >
30-days-of-react-ebook-fullstackio.pdf
Join us tomorrow when we jump into our first React app. ... First, we'll need to import the PropTypes object from the prop-types...
Read more >
Crashlytics - React Native Firebase
Crash reports: Every crash is automatically turned into a crash report and sent. Stack traces: Even when an error is caught and your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found