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

Webpack 5 compatibility #439

Closed
ryuran opened this issue Oct 13, 2019 · 6 comments
Closed

Webpack 5 compatibility #439

ryuran opened this issue Oct 13, 2019 · 6 comments

Comments

@ryuran
Copy link

ryuran commented Oct 13, 2019

Hello

I think it's because Webpack 5 remove Node.js polyfills

I try to update webpack@next and i have an error on utf8-binary-cutter dependency of twing.

ERROR in   Error: ./node_modules/utf8-binary-cutter/lib/utf8-binary-cutter.js?:13
  var DEFAULT_TRUNCATE_STRING_BINARY_SIZE = Buffer.byteLength(DEFAULT_TRUNCATE_STRING, 'utf8');
                                            ^
  ReferenceError: Buffer is not defined

  - utf8-binary-cutter.js?:13 eval
    [.]/[utf8-binary-cutter]/lib/utf8-binary-cutter.js?:13:43
@ericmorand
Copy link
Member

I assume this error occurs with every package that makes use of Buffer, right?

@ryuran
Copy link
Author

ryuran commented Oct 15, 2019

I think.
I only meet this error when I move to webpack v5 on a simple project using htmlWebpackPlugin, twing-loader ans a simple Twig file as template for index.html.

@ericmorand
Copy link
Member

It is expected. Twing is Buffer based - needed to support encoding as Twig specification enforces.

Is there an available polyfill for webpack v5?

@ryuran
Copy link
Author

ryuran commented Oct 16, 2019

Ok I read some doc about it.

Webpack v5 recommand to use browser entry in package.json to manage alternative for browser.
In this way we can add a polyfill like https://github.com/feross/buffer.

I think it's the way, it can be useful to make twing able to be run in browser.

I try to ask more question about it webpack/changelog-v5#10

@ericmorand
Copy link
Member

Do we need to change something here? Twing already comes with a browser specific flavor (via the browser field of package.json) so I assume the polyfill needs to be added at the bundler level and that should do the trick.

@ericmorand
Copy link
Member

I close, feel free to reopen is the issue is still legit.

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

2 participants