denoland / denoland/deno-rolldown-plugin

Fails to resolve npm packages with subpath exports or complex module structures

Open
#8 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
31
Forks
2
PR merge metrics
No merged PRs in 30d

Description

#### Bug Report

When bundling projects using `@deno/rolldown-plugin`, builds frequently fail with module resolution errors when encountering npm dependencies with non-trivial package layouts. The resolution logic appears to struggle with common patterns like subpath exports and deeply nested module files.

The issues seem to stem from the underlying npm resolution mechanism, likely within `@denoland/deno-js-loader`, which is unable to correctly interpret the package structure, leading to different kinds of errors.

I've identified at least two distinct failure modes.

---

#### Example 1: Incorrect Subpath Resolution

This error occurs when a package uses subpath exports. The resolver incorrectly assumes a directory-plus-index-file structure instead of respecting the package's export map.

**Minimal Reproducible Example (using Radix UI):**
Deno 2.4.0
**`deno.json`:**
```json
{
"imports": {
"react": "npm:react@^19",
"react-dom": "npm:react-dom@^19",
"radix-ui": "npm:radix-ui@^1.4.2"
}
}
```

**`main.tsx`:**
```tsx
import { Accordion } from "radix-ui";

console.log(() => );
```

**`mod.ts` (build script):**
```ts
import denoPlugin from "@deno/rolldown-plugin";
import { defineConfig, rolldown } from "rolldown";

try {
const rolldownConfig = defineConfig({
input: ["./main.tsx"],
output: { file: "out.js" },
plugins: [denoPlugin({ configPath: "deno.json" })],
});
const buildInstance = await rolldown(rolldownConfig);
await buildInstance.write(rolldownConfig.output);
} catch (error) {
console.error(error);
}
```

**Error Output:**

```
Error: Build failed with 1 error:

[plugin deno-plugin]
Error: [ERR_MODULE_NOT_FOUND] Cannot find module 'file:///Users/app/Library/Caches/deno/npm/registry.npmjs.org/react-remove-scroll-bar/2.3.8/constants/index.js' imported from 'file:///Users/app/Library/Caches/deno/npm/registry.npmjs.org/react-remove-scroll/2.7.1/dist/es5/UI.js'
```

**Analysis:**
The resolver fails on an import for `react-remove-scroll-bar/constants`. It attempts to load `.../constants/index.js`, which does not exist. The correct file (e.g., `dist/es5/constants.js`) should be determined by the `package.json` exports map, but this seems to be ignored.

---

#### Example 2: Failure to Find Referrer Package

This error occurs with other packages, suggesting the loader is unable to associate a file deep within a package's directory with its parent `package.json`.

**Error Output (from a different project using `@base-ui-components/react`):**

```
[plugin deno-plugin]
Error: Could not find referrer npm package 'file:///Users/app/Library/Caches/deno/npm/registry.npmjs.org/@base-ui-components/react/1.0.0-beta.1/esm/accordion/header/AccordionHeader.js' (@base-ui-components/react@1.0.0-beta.1).
at __wbindgen_error_new (https://jsr.io/@deno/loader/0.1.3/src/lib/rs_lib.internal.js:978:15)
...
```

**Analysis:**
This error message indicates that while processing a nested file (`.../esm/accordion/header/AccordionHeader.js`), the loader failed to determine the npm referrer package. This is another critical failure in understanding npm package structure.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.