Skip to content

Cannot implement import attribute with { type: "external" } #3646

Closed

Description

@brillout

I'm trying to implement this:

// Not externalized
import { something } from 'some-package'
// Externalized
import { something } from 'some-package' with { type: "external" }

In other words:

build.onResolve({filter: /.*/}, async (args) => {
  if (args.kind !== 'import-statement') return undefined
  if (args.with === 'external') {
    return { external: true, /*...*/ }
  }
  // ...
})

That would work but the issue is that args.with is missing at onResolve(). It seems to be provided only to onLoad().

Is there a way to implement such import attribute?

Activity

  1. evanw commented on Feb 20, 2024

    @evanw
    Owner

    This is not currently supported, but it's something to add to esbuild in the future. I think this issue is related to at least #3384 and #3639.

  2. sod commented on Feb 21, 2024

    @sod
    Contributor

    Keep in mind that

    build.onResolve({filter: /.*/}, async (args) => {

    is a pretty punishing operation. What you ask from esbuild here is call a javascript method on every single import statement, which blocks esbuild from grinding through your project as fast as possible, as it can only pick the next file when your resolver answered. Even if this took only a millisecond to answer, on 1000 import statements you added 1 second of overhead.

  3. magoniac commented on Apr 16, 2024

    @magoniac

    It might turn out to be a really handy option. As for possible performance issues I saw someone had suggested to introduce extra filtering property, smth. like { filter: /.*/, withType: "external" }.

  4. added a commit that references this issue on May 24, 2024
    4ad11c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions