Skip to content

Implement synchronous import.meta.resolve(…) #2472

@lgarron

Description

@lgarron

What is the problem this feature would solve?

It is common to write apps and library code in JS that references relative file paths, such as:

  • Dynamic JS entry files (in particular, for web workers/service workers/shared workers)
  • WASM
  • CSS, JSON, arbitrary resources, …

import.meta.resolve(…) provides a standard way to refer to a relative resource, and also supports bare names and absolute paths. It is already supported in all major browsers and deno. It would be valuable for import.meta.resolve(…) to be available in all target environments, including bun.

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

Implement https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve

What alternatives have you considered?

As a library author, I can use code that uses new URL(…, import.meta.url).href instead. However:

  • import.meta.resolve(…) is more ergonomic and conveys clear intentions compared to being a "magic pattern", and
  • it is not supported by all bundlers, and it's unclear if it ever will be (possibly due to the previous reason).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions