Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer is undefined when running webpack 5 and angular. #27

Closed
srenbo opened this issue Nov 9, 2021 · 7 comments
Closed

Buffer is undefined when running webpack 5 and angular. #27

srenbo opened this issue Nov 9, 2021 · 7 comments
Assignees

Comments

@srenbo
Copy link

srenbo commented Nov 9, 2021

The newest iteration of angular does not include Node.js modules in the build, which means Buffer is not included.

This leads to a Buffer is not defined error when using til lib.

I've fixed it in my build by adding the 'buffer' package and adding

const Buffer = require('buffer/').Buffer;

to request.js

@filiphric
Copy link

I’m also facing this issue, would adding buffer to the request.js file make sense for this package?

@marcelobrito
Copy link

webpack/changelog-v5#10

@filiphric
Copy link

thanks @marcelobrito, I read this. however I’m facing the same problem but not with webpack but with vite. adding the mentioned import into request.js file solves it there as well, that’s why it made sense to me to update this package. But I’m assuming that I may have a knowledge gap into what is actually happening with the whole buffer thing 🤔

@jm-mailosaur
Copy link
Contributor

jm-mailosaur commented Dec 6, 2021

@marcelobrito @filiphric Just to confirm - are you using the library in the browser? Buffer should be globally defined in Node, but I'm assuming you're packing code for a browser-based implementation?

Edit: For context, the cypress-mailosaur plugin should actually get executed 'server-side' (i.e. the request.js file should never get invoked in a browser), which is what leads me to the question.

@filiphric
Copy link

@hippyhorse yeah it’s executed in browser, but Cypress tests are executed in browser. I’m not sure how would it be possible to execute mailosaur plugin on server side when running in Cypress, can you give me an example of what you have in mind?

@jm-mailosaur jm-mailosaur self-assigned this Dec 13, 2021
@jm-mailosaur
Copy link
Contributor

@filiphric Whilst Cypress tests and most commands are executed in the browser, several of the plugin aspects use a Node.js runtime behind the scenes (which is what I believe allowed Buffer to work in our tests here). Either way, we've just pushed version 2.6.0 which has a polyfill that uses btoa if available instead.

Let us know if this works on your side!

@jm-mailosaur
Copy link
Contributor

Closing issue as we believe this is now fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants