evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.58k stars 1.11k forks source link

Could not resolve "path", could not resolve "os" #3799

Open markskayff opened 2 weeks ago

markskayff commented 2 weeks ago

When trying to build a react project doing: npm run build-dev I get a lot of Could not resolve "path" Could not resolve "os" Could not resolve "crypto"

And of course the build fails. I'm building for the browser.

I have to note I'm using this plugin:

const envFilePlugin = require('esbuild-envfile-plugin');

could-not-resolve

evanw commented 2 weeks ago

The browser does not provide packages such as os, so these packages are not available when building for the browser. If you want to substitute them for other ones, you should be able to use either the alias feature or a plugin for that.

hyrious commented 2 weeks ago

That plugin (and most esbuild plugins) are meant to run in the Node.js runtime. While your error message seems that you're bundling that plugin into your browser bundle, which is incorrect.

markskayff commented 2 weeks ago

That plugin (and most esbuild plugins) are meant to run in the Node.js runtime. While your error message seems that you're bundling that plugin into your browser bundle, which is incorrect.

Definitely I'm building for the browser here. But the odd part is this, it's a project I'm resuming from 1 year, which it was working ok, and now trying to re-build it, and it's complaining with this. That's odd.