Skip to content

Conversation

@jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Dec 8, 2025

This PR implements the same thing as #73422, but as part of esbuild onResolve callback, without a separate post-processing step with Babel.

Local imports like import from './proxy' are resolved either to './proxy.js' or './proxy/index.js', depending on which file/directory exists. That way the imports become compatible with Node.js ESM import rules, and also with browsers' native ESM import rules. They both require full file paths, without any shortcuts.

I originally wanted to eliminate local imports completely in #73516, but that proved too ambitious and risky.

This esbuild approach is very simple and flexible. If we want to, we can easily modify it to make all imports use the .mjs or .cjs extension. That will be useful for creating fully compliant dual CJS/ESM packages.

Before we merge this, I'd like to fine-tune the algorithm a bit. Make sure that special paths like '.' and '..' are handled correctly, that imports with an existing non-JS extension (like block.json) are not handled with this code, etc. But I didn't want to delay the PR further. Let's test and review.

@jsnajdr jsnajdr self-assigned this Dec 8, 2025
@jsnajdr jsnajdr added [Type] Build Tooling Issues or PRs related to build tooling [Package] wp-build /packages/wp-build labels Dec 8, 2025
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] wp-build /packages/wp-build [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants