esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Running esbuild under npm explore no longer works

Open ComLock opened this issue 1 year ago • 1 comments

I believe the problem was introduced by the externals change in 0.16.0

Prevent entry files to be marked as externals https://github.com/evanw/esbuild/issues/2382

Originally I thought the problem was in tsup:

tsup no longer works with npm explore https://github.com/egoist/tsup/issues/1110

I think the problem is that when esbuild is run via npm explore, it is run inside a node_modules folder, so it tries to mark all files as external, which means no files inside that folder can be "used", since everything is marked as external.

The error message is:

The entry point "/private/tmp/myproject/node_modules/@enonic/react4xp/tsup.config.client.ts" cannot be marked as external

So I'm assuming tsup is using esbuild to transpile tsup.config.client.ts to tsup.config.client.js, before using it as configuration for the actual build. So tsup has tsup.config.client.ts as an entrypoint, and esbuild complains because it has marked everything under it's parent, parent, parent (node_modules) as external, and an entrypoint can't be an external.

Hmm, perhaps the fix is for tsup to explicitly avoid marking anything as external?

ComLock avatar Apr 29 '24 09:04 ComLock

tsup uses bundle-require to load its options, which runs esbuild with a custom resolver plugin that intentionally marks all paths with node_modules as external:

https://github.com/egoist/bundle-require/commit/61f98ee

In fact, there's a similar issue raised in that repo: https://github.com/egoist/bundle-require/issues/42

I believe this is not an issue with esbuild. esbuild do have an option --packages=external but this will not wrongly mark the entry point as external when the entry is in node_modules.

hyrious avatar Apr 29 '24 09:04 hyrious

I'm closing this issue as it sounds like it's related to a plugin, and not to esbuild itself.

evanw avatar May 25 '24 00:05 evanw