remorses/esbuild-plugins

Cannot set property Buffer of #<Object> which has only a getter

Closed this issue · 0 comments

Trying to build webtorrent using esbuild with Globals and Modules polyfills, I get the following error:

    at node-modules-polyfills-commonjs:buffer (node-modules-polyfills-commonjs:buffer:12)
    at __require (out.js:12)
    at node_modules/safe-buffer/index.js (index.js:3)
    at __require (out.js:12)
    at node_modules/bencode/lib/encode.js (encode.js:1)
    at __require (out.js:12)
    at node_modules/bencode/lib/index.js (index.js:3)
    at __require (out.js:12)
    at node_modules/create-torrent/index.js (index.js:2)
    at __require (out.js:12)

my build code:

import NodeModulesPolyfillPlugin from '@esbuild-plugins/node-modules-polyfill'
import NodeGlobalsPolyfillPlugin from '@esbuild-plugins/node-globals-polyfill'
import ESBuild from 'esbuild'

ESBuild.build({
  plugins: [NodeModulesPolyfillPlugin.default(),
    NodeGlobalsPolyfillPlugin.default({
      process: true,
      buffer: true
    })],
  entryPoints: ['index.js'],
  bundle: true,
  sourcemap: true,
  format: 'esm',
  target: ['esnext'],
  platform: 'browser',
  outfile: 'out.js',
  define: {
    global: 'globalThis'
  }
}).catch(() => process.exit(1))

additionally in package.json I specified "type": "module",
I run the script via node build.js