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.

ReactPDF.render is not a function

See original GitHub issue

OS: macOS High Sierra v.10.13.6

React-pdf version: 1.0.0-alpha.14

Description: When I am trying to render the ReactPDF in the componentWillMount I am getting the error __WEBPACK_IMPORTED_MODULE_1__react_pdf_renderer__.f.render is not a function. Below is the full code snippet. My goal is to download a version of the PDF on the mounting of a page and show a loading screen to the user. Please let me know if anyone has faced this issue or knows the solution! Cheers!

import React, { Component } from 'react'
import ReactPDF, { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer'

import autobind from 'react-autobind'

class Container extends Component {
  constructor (props) {
    super(props)

    this.state = {
      demographics: [],
      isDataLoaded: false,
    }

    autobind(this)
  }

  componentWillMount () {
    ReactPDF.render(<MyDocument />, `${__dirname}/example.pdf`)
  }

  render () {
    return (
      <Main />
    )
  }
}

// Create styles
const styles = StyleSheet.create({
  page: {
    flexDirection: 'row',
    backgroundColor: '#E4E4E4',
  },
  section: {
    margin: 10,
    padding: 10,
    flexGrow: 1,
  }
})

// Create Document Component
const MyDocument = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <Text>Section #1</Text>
      </View>
      <View style={styles.section}>
        <Text>Section #2</Text>
      </View>
    </Page>
  </Document>
)

const Main = () => (
  <div>loading pdf</div>
)

export default Container

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
diegomuracommented, Aug 10, 2018

Hey. If you read the README you will see that ReactPDF.render is the mounter function for generating documents using Node (server-side). You’re using the lib in a web environment. There’s an open issue about generating documents on the fly. It’s not something completely solved, but please refer to it

3reactions
moffsugitacommented, Nov 30, 2018

@diegomura README says that ReactPDF.render only “Save in a file”. I used resume example and replace react-pdf.es.jsto @react-pdf/renderer. And I used ReactDOM.render(<MyDocument />, document.getElementById('root')); for client side.

However it shows just text…

2018-11-30 15 18 49

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-pdf/renderer on production gives an error this.subset ...
@react-pdf/renderer on production gives an error this.subset.encodeStream is not a function · javascript · reactjs · typescript · pdf · webpack.
Read more >
react-pdf - npm
A prop that behaves like ref, but it's passed to main <div> rendered by <Document> component. n/a. Function: (ref) => { this.myDocument =...
Read more >
Options - React PDF Viewer
`renderLoader`, `Function`, The loader renderer, 2.0.0 ... If it's not set, the initial zoom level will be calculated based on the dimesion of...
Read more >
Page wrapping - React-pdf
If that's not what you need, you can disable this very easily by doing: import { Document, Page } from '@react-pdf/renderer' const doc...
Read more >
document.getElementById(...).render is not a function - React.js
I wasted again another hour of my life finding this solution.
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