What is the work around of not being able to use `--platform=node` in the esbuild arguments?

I get the following error when I add the get-pixels library:

3 │ var path = require(‘path’)
╵ ~~~~~~

The package “path” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “–platform=node” to do that, which will remove this error.

but when I add --platform=node to esbuild arguments I get this error (in the browser console):

Uncaught ReferenceError: require is not defined

What is the work around this issue?

Written in 100% JavaScript, works both in browserify and in node.js and has no external native dependencies.


To run this in a browser it seems to require the shims of browserify. Setting --platform=node will make esbuild not complain, because it expects you to use node for running the results. But your browser is not node, so you just shifted the detection of the problem elsewhere.

1 Like

That actually clarified things up