Skip to content

fix(extensions): resolve folder-extension node_modules imports in compiled binaries - #1141

Open
mvanhorn wants to merge 1 commit into
modem-dev:mainfrom
mvanhorn:fix/1136-compiled-folder-extension-imports
Open

mvanhorn wants to merge 1 commit into
modem-dev:mainfrom
mvanhorn:fix/1136-compiled-folder-extension-imports

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Summary

After the host-specifier rewrite, onLoad runs rewriteInstalledPackageSpecifiers on the transpiled source of every file under the extension directory, including packages installed inside it. Each static bare specifier in import, export-from, import(), or require() is replaced with the file installed for it: a file URL for the module forms, and an escaped absolute path for require(). Resolution uses Bun.resolveSync when that path exists on disk, then createRequire from the importer, then the package root import or default export when require cannot read an import-only exports map. Relative paths, Node and Bun builtins, hunk-host and file URLs, and packages neither resolver can find stay as written, so a missing package still fails with the existing error.

A folder extension that imports a package installed in its own node_modules fails to load when Hunk is the compiled binary. The status bar reports that the package cannot be found from the extension entry, and the extension action does nothing. The same package imported by a relative path into that node_modules loads. Extension source is returned as contents from the Bun plugin onLoad hook after transpilation. In a compiled binary those bare specifiers are not resolved from the extension file, so the folder-local node_modules is never opened. Relative specifiers still resolve from that file.

Verification

  • ./scripts/quality/source-boundaries.test.ts could not run in this environment (./scripts/quality/source-boundaries.test.ts is not executable).
  • The JavaScript test command did not run the new host runtime module tests.
  • The source-boundaries check did not execute.

Fixes #1136

…piled binaries

After the host-specifier rewrite, onLoad runs
rewriteInstalledPackageSpecifiers on the transpiled source of every file
under the extension directory, including packages installed inside it.
Each static bare specifier in import, export-from, import(), or
require() is replaced with the file installed for it: a file URL for the
module forms, and an escaped absolute path for require(). Resolution
uses Bun.resolveSync when that path exists on disk, then createRequire
from the importer, then the package root import or default export when
require cannot read an import-only exports map. Relative paths, Node and
Bun builtins, hunk-host and file URLs, and packages neither resolver can
find stay as written, so a missing package still fails with the existing
error.

Fixes modem-dev#1136
@greptile-apps

greptile-apps Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

@mvanhorn is attempting to deploy a commit to the Modem Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Folder extensions can't import packages from their own node_modules in the compiled binary ("Cannot find package")

1 participant