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.

ReferenceError: _a is not defined

See original GitHub issue

Describe the bug

Node version: 8.10.0 Project’s react/react-dom version: 16.3.2 Hello! thanks for this awesome library!

I’m at my wit’s end trying to make it work with our project, but I can’t (yet) make it work

I tried investigating (as the error explicitly says it’s on yoga-layout-prebuilt) but everyone here seems to have no problem with the prebuilt library.

I upgraded React to 16.8.3 as well but to no avail. I noticed on other issues that there’s a mention on a “proper webpack” configuration, not sure if this is a “proper” one:

To Reproduce

Document component:

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



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>
);

Code:

export default MyDocument


View:
import { PDFViewer } from '@react-pdf/renderer';
import MyDocument from 'document';

... 
render(){
return (
   ...some divs here...
     <PDFViewer
          >
            <MyDocument/>
          </PDFViewer>
);
}

Expected behavior Samples to work

Screenshots

image

Desktop (please complete the following information):

  • OS: MacOS Mojave 10.14.5
  • Browser Chrome 75.0.3770.100
  • React-pdf version “@react-pdf/renderer@^1.6.3”: version “1.6.3”

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
jehanreycommented, Oct 19, 2020

We encountered this issue while trying to integrate this cool library in our app. I tried the solutions suggested by @mphealy. At first the 1st option was working fine locally, however I was encountering build problems. I ended up going for the 2nd option and using npx patch-package to get it to work.

3reactions
mphealycommented, Sep 10, 2019

I experienced this error as well and have 2 possible work arounds. I believe the issue is this: nbind.js has an undeclared variable. when your project is built it pulls in nbind.js during minification to the main js file, which has “option strict”, causing the error you see.

Option 1 In the .babelrc file at the root of your project add the following: "ignore": [ "node_modules/yoga-layout-prebuilt" ]

Option 2 Declare the variable in nbind.js: Open node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js On line 1146 find this: _a = _typeModule(_typeModule), and change to this: var _a = _typeModule(_typeModule);

Unfortunately we ultimately went with option 2. Another downside to this prebuilt nbind yoga c++ mapping - it automatically allocates 128MB of memory upon initialization which can be seen on lines 460 and 464 of nbind.js. While this would not be an issue for most, our requirement is to support IE 11 (yes, I do know what year it is). IE leaks this memory with each page refresh and eventually crashes the process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: "x" is not defined - JavaScript - MDN Web Docs
ReferenceError : "x" is not defined. The JavaScript exception "variable is not defined" occurs when there is a non-existent variable referenced somewhere.
Read more >
Uncaught ReferenceError: $ is not defined? - Stack Overflow
The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library ......
Read more >
How to Fix ReferenceError: Event is Not Defined in JavaScript
The Javascript ReferenceError occurs when referencing a variable that does not exist or has not yet been initialized in the current scope.
Read more >
How to Fix Uncaught ReferenceError: $ is not defined in jQuery
The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file...
Read more >
ReferenceError: "x" is not defined - JavaScript
There is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in...
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