oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.3k stars 2.69k forks source link

Bun.build: improve error message when Node.js builtin cannot be resolved #3114

Open TommasoAmici opened 1 year ago

TommasoAmici commented 1 year ago

What is the problem this feature would solve?

When bundling applications with bun build I've run into this error message:

bun build ./src/index.tsx

error: Could not resolve Node.js builtin: "module". To use Node.js builtins, set target to 'node' or 'bun'

const Module = require('module');
                       ^
../node_modules/import-fresh/node_modules/resolve-from/index.js:3:24 67

This code is not used directly in my application, so it must be used in some imported library, however it's pretty much impossible to figure out which one

What is the feature you are proposing to solve the problem?

it'd be nice to have a more verbose build log, perhaps behind a --verbose flag if you think it'd pollute the output, to print extra information that could help hunt down the problem

What alternatives have you considered?

No response

Jarred-Sumner commented 1 year ago

Can you try passing --target=bun or --target=node to to bun build?

TommasoAmici commented 1 year ago

With --target=node or --target=bun I don't have this issue, but I was under the impression that since I'm targeting browsers I should stick to the default --target=browser.

EDIT: I reread my initial message and I realize I didn't make this clear, sorry about that! I'm trying to migrate a project from CRA to use bun at least when developing locally

uson1x commented 1 year ago

We also target browser in our app, but have lingui dependency, which in turn has the same resolve-from dependency, where bun build fails for us.

We use lingui both in runtime for fetching localisation strings and when building for extracting. Not sure if this use-case might be supported in future in bun or if we can use some workaround now?

muratangin187 commented 1 year ago

We also got the same issue with a regular website build. It is same, from resolve-from which I don't use directly but some react packages uses. When I set target to node and try to run in on browser, it fails.