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.

Can't get it to work - Buffer is not defined

See original GitHub issue

OS: macOs 10.13.4

React-pdf version:@react-pdf/renderer”: “^1.0.0-alpha.17”,

Description: I am having trouble simply installing it into my app. I run npm install @react-pdf/renderer --save and I see the following issues in the tree…

├── UNMET PEER DEPENDENCY react@16.5.2
└── UNMET PEER DEPENDENCY react-dom@16.5.2

Then when I add the following to a file… import { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer';

I receive the following error…

Uncaught Reference Error: Buffer is not defined

Here is my package.json…

"dependencies": {
    "@fortawesome/fontawesome": "^1.1.5",
    "@fortawesome/fontawesome-free-solid": "^5.0.10",
    "@fortawesome/react-fontawesome": "0.0.18",
    "@react-pdf/renderer": "^1.0.0-alpha.17",
    "antd": "^2.10.4",
    "bcrypt": "^1.0.3",
    "fabric": "^2.2.1",
    "griddle-react": "^1.13.1",
    "image-compressor.js": "^1.1.3",
    "jquery": "^3.1.1",
    "moment": "^2.22.2",
    "prop-types": "^15.6.2",
    "react": "^16.5.2",
    "react-collapse": "^4.0.3",
    "react-color": "^2.13.8",
    "react-dom": "^16.5.2",
    "react-icons": "^2.2.7",
    "react-router": "^3.0.0",
    "react-sortable-hoc": "^0.6.8",
    "rgba-convert": "^0.3.0"
  },
  "engines": {
    "node": "4.8.1"
  },
  "devDependencies": {
    "babel-plugin-transform-class-properties": "^6.24.1",
    "enzyme": "^2.7.1",
    "expect": "^1.20.2"
  },
  "babel": {
    "plugins": [
      "transform-class-properties"
    ]
  }

Where am I going wrong here? Do I need to be on a specific version of react? I also tried adding "buffer": "^5.1.0", to my package.json file but the error still shows up.

Any help would be very much appreciated.

Thanks

How to replicate issue including code snippet (if applies):

You can make use of react-pdf REPL to share the snippet

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
xididricommented, Feb 4, 2019

@diegomura could you share what you used to fix this ? I’m facing the same issue and tried various things from the thread linked but still get the error.

Meteor.startup(() =>
{
	global.Buffer = function() {};
	global.Buffer.isBuffer = () => false;
	render(<Root />, document.getElementById('root'));
});
  1. npm install buffer
import Buffer from 'buffer';

if (typeof this.Buffer === 'undefined') {
  this.Buffer = Buffer.Buffer;
}
  1. meteor npm install meteor-node-stubs

Meteor 1.8

Edit : fixed by npm install meteor-node-stubs (none of the above is needed).

0reactions
tahaziadehcommented, Apr 30, 2020

for Meteor 1.8.1 This solution worked for me meteor npm uninstall --save meteor-node-stubs meteor npm install --save meteor-node-stubs

Reference: https://mopethis.wordpress.com/2019/08/11/meteor-update-buffer-is-not-defined/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught ReferenceError: Buffer is not defined - Stack Overflow
Answering my own question. Two things helped to resolve the issue: Adding plugins section with ProviderPlugin into webpack.config.js.
Read more >
Uncaught ReferenceError: Buffer is not defined #2248 - GitHub
If you just try to use Buffer on the client, it compiles but you get runtime error: ReferenceError: Buffer is not defined.
Read more >
Buffer is not defined. Using Phantom Wallet, Solana and ...
I've created a simple app to figure out how to use a Phantom wallet to make Solana transactions. I ...
Read more >
Porting to the Buffer.from() / Buffer.alloc() API - Node.js
js (node:7147) [DEP0005] DeprecationWarning: The Buffer() and new Buffer() constructors are not recommended for use due to security and usability concerns.
Read more >
Walletconnect help - General - Algorand Forum
I'm trying to integrate walletconnect into my app in react. I get an error in the console: buffer is not defined when pressing...
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