esbuild-plugins icon indicating copy to clipboard operation
esbuild-plugins copied to clipboard

No matching export in "node-modules-polyfills:buffer" for import "default"

Open keithbro-imx opened this issue 3 years ago • 3 comments

Hello!

I'm not sure if this is an issue with node-modules-polyfills or with the way that the library that I'm trying to use is built, but when I try to use https://github.com/wanseob/soltypes, and build my app, I get the following error:

✘ [ERROR] No matching export in "node-modules-polyfills:buffer" for import "default"

    node_modules/soltypes/build/index.es.js:1:7:
      1 │ import buffer from 'buffer';
        ╵        ~~~~~~

I've created a minimal repro here: https://github.com/keithbro-imx/buffer-polyfills-repro

For context, I ran in to this issue when using this library in a Remix app.

Would be great to get your thoughts on where the problem might be and how we might fix it.

Thanks in advance for your help!

keithbro-imx avatar Mar 16 '22 22:03 keithbro-imx

The problem is in the polyfill library, unfortunately the library won’t accept PRs and I don’t want to maintain a fork, maybe I should try again searching for an alternative polyfill

remorses avatar Mar 18 '22 19:03 remorses

You can also give a try to https://github.com/niksy/node-stdlib-browser

remorses avatar Mar 18 '22 20:03 remorses

If you use yarn v2 or pnpm, you can patch this package using package manager's patch command.

An example for patch:

diff --git a/build/index.es.js b/build/index.es.js
index 8f8e4779c39e381c13ed51ab6d608f1648c70d62..fa37bd4ba1d15417adf31019c7236ee16022b20e 100644
--- a/build/index.es.js
+++ b/build/index.es.js
@@ -1,4 +1,4 @@
-import buffer from 'buffer';
+import { Buffer } from 'buffer';
 
 /*! *****************************************************************************
 Copyright (c) Microsoft Corporation.
@@ -85,12 +85,6 @@ var bn = createCommonjsModule(function (module) {
   BN.BN = BN;
   BN.wordSize = 26;
 
-  var Buffer;
-  try {
-    Buffer = buffer.Buffer;
-  } catch (e) {
-  }
-
   BN.isBN = function isBN (num) {
     if (num instanceof BN) {
       return true;

Garfield550 avatar Feb 21 '23 05:02 Garfield550