Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Specify out extension for .js AND .mjs files #4021

Open
cquillen2003 opened this issue Dec 29, 2024 · 2 comments
Open

Feature Request: Specify out extension for .js AND .mjs files #4021

cquillen2003 opened this issue Dec 29, 2024 · 2 comments

Comments

@cquillen2003
Copy link

If an out extension is specified for .mjs files an error occurs:

outExtension: { '.mjs': '.mjs' }

[ERROR] Invalid output extension: ".mjs" (valid: .css, .js)

For example, I am trying to include an .mjs file from an external library (sqlite3-worker1-bundler-friendly.mjs in my case) in my outdir but that is not easily doable it appears.

@hyrious
Copy link

hyrious commented Jan 3, 2025

You can just bundle twice with:

  • Bundle sqlite3-worker1-bundler-friendly.mjs with
    outExtension: { '.js': '.mjs' }`
  • Bundle the rest of your code, with the file bundled above externalized:
    external: ['./sqlite3-worker1-bundler-friendly.mjs']
    which assumes your code is like
    // entry.js
    import './sqlite3-worker1-bundler-friendly.mjs'

@evanw
Copy link
Owner

evanw commented Jan 3, 2025

The reason that outExtension only accepts at most two values is that the mapping only remaps the output path that esbuild generates and esbuild's bundler currently only supports two types of output files (CSS and JavaScript). The outExtension map doesn't match on any input file extension because they have been processed away by the time the bundler is writing files out. Allowing more values in that map would be confusing because they wouldn't do anything, as esbuild wouldn't use them.

You haven't described enough about your problem for me to understand what you're trying to do. Here are the issue reporting instructions that you deleted when posting this issue:

When reporting a bug or requesting a feature, please do the following:

  • Describe what esbuild is doing incorrectly and what it should be doing instead.

  • Provide a way to reproduce the issue. The best way to do this is to demonstrate the issue on the playground (https://esbuild.github.io/try/) and paste the URL here. A link to a minimal code sample with instructions for how to reproduce the issue may also work. Issues without a way to reproduce them may be closed.

You have not provided a way to reproduce the issue, so it's not clear to me what's wrong or what should be done about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants