evanw / evanw/esbuild

Is it possible to customize the [dir] in entryNames?

Open
#3,702 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

First thank you so much for esbuild. It is an absolute joy to work with!

### Issue

I'm running into an issue where I need to bundle some files from a directory in `node_modules`.

```js
await build({
entryPoints: [
'./src/**/*.page.js',
'./node_modules/some-module/files/**/*.page.js'
],
bundle: true,
entryNames: '[dir]/[name]',
outbase: "./",
outdir: './dist',
platform: 'node',
format: 'esm',
});
```

This code works, but the output in `./dist` ends up containing a folder called `node_modules/`, which causes node to think that files under that path are actual node modules. Since that output directory doesn't contain a package.json, node thinks it's a CommonJS module and gets confused to why there's an ESM file in there.

### Minimal reproduction

https://github.com/ryanto/esbuild-entrynames-dir

### Temp fix I'm using

As a temporary fix, I have dropped `[dir]` from `entryNames` so that no folder named `node_modules` will end up in `./dist`. I am using `entryNames: [name]-[hash]`, but I am worried I am going to get a collision due to the large number of files I'm building with similar names. I would love to add [dir] back because it makes debugging and viewing build output easier for me.

It would be great if I could customize the name of the output file to ensure that there's no `node_modules` name in it's path. I think this might be possibility related to the `onEmit` plugin API mentioned in https://github.com/evanw/esbuild/issues/553

Again thank you so much for esbuild!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked minimal reproduction and the entryNames/outbase options shown in the issue. Trace how [dir] produces the node_modules directory and determine what customization is needed; done means output paths can avoid node_modules while retaining useful directory structure without collisions.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.