Skip to content

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

Description

@cdl

What happened?

The rendered-markdown example extension fails to load in the compiled hunk binary:

Extension rendered-markdown failed to load • Cannot find package 'marked' imported from /Users/<me>/.config/hunk/extensions/rendered-markdown/index.ts

marked is installed in the extension's own node_modules, which the folder extension docs say is supported.

Environment: macOS 26 (Darwin 25.6.0, arm64), Ghostty 1.3.2, zsh. hunkdiff is installed globally with Bun 1.4.2 (it runs the hunkdiff-darwin-arm64 binary). config.toml has no [extensions] settings.

Workaround: Importing by relative path loads fine, and F8 renders the Markdown:

import { Lexer, type Token, type Tokens } from "./node_modules/marked/lib/marked.esm.js";

Suspected cause (unconfirmed): registerHostRuntimeModules (packages/hunk/src/extensions/hostRuntimeModules.ts) serves extension files through a Bun.plugin onLoad hook that returns transpiled contents. My guess is that inside a bun build --compile binary, bare specifiers in that returned code aren't resolved from the importing file's directory, while relative ones are. The folder-local node_modules coverage from #606 may only run from source.

Steps to reproduce

git clone --depth 1 https://github.com/modem-dev/hunk
mkdir -p ~/.config/hunk/extensions
cp -R hunk/examples/extensions/rendered-markdown ~/.config/hunk/extensions/
(cd ~/.config/hunk/extensions/rendered-markdown && bun install)   # installs marked@17.0.1

cd "$(mktemp -d)"
printf '# Hi\n\nold\n' > before.md
printf '# Hi\n\n**new** text\n' > after.md
hunk diff --files before.md after.md

The load error appears in the status bar, and F8 does nothing.

Expected behavior

The extension loads, and F8 (View → File presentation: Rendered Markdown) shows the rendered Markdown view.

Version

0.23.0

Activity

  1. added
    bugSomething isn't working
    on Sep 30, 2026
  2. mvanhorn commented on Oct 4, 2026

    @mvanhorn
    Contributor

    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.

    After the host-specifier rewrite, onLoad runs rewriteInstalledPackageSpecifiers on the transpiled source of every file under the extension directory, including packages installed inside it.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions