Self-referencing imports (own package name) produce `UNRESOLVED_IMPORT` warnings
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 432
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
If a bundled entry imports the package by its own name (Node's package self-referencing through exports), obuild prints UNRESOLVED_IMPORT warnings.
Here is why. obuild marks only dependencies and peerDependencies as external (src/builders/bundle.ts#L93-L101), and the package's own name isn't one of them. So Rolldown tries to resolve pkg/foo through exports, which points into dist/. obuild has just cleaned dist/, so the lookup fails and Rolldown warns before treating the import as external.
The output itself is correct, since the specifier is kept and resolves at runtime. The problem is noise: one warning block per self-import. In env-runner that's 8 blocks on every build, from src/loader.ts lazily importing env-runner/runners/<name>.
Reproduction
package.json
{
"name": "pkg",
"type": "module",
"exports": { ".": "./dist/index.mjs", "./foo": "./dist/foo.mjs" },
"devDependencies": { "obuild": "^0.4.40" }
}
build.config.mjs
import { defineBuildConfig } from "obuild/config";
export default defineBuildConfig({
entries: [{ type: "bundle", dts: false, input: ["src/index.ts", "src/foo.ts"] }],
});
src/foo.ts
export const foo = "foo";
src/index.ts
export const load = () => import("pkg/foo").then((m) => m.foo);
$ pnpm obuild
🧻 Cleaning up ./dist
src/index.ts (1:33) [UNRESOLVED_IMPORT] Could not resolve 'pkg/foo' in src/index.ts
...
╰── Module not found, treating it as an external dependency
✅ obuild finished in 71ms
$ cat dist/index.mjs
const load = () => import("pkg/foo").then((m) => m.foo);
export { load };
$ node -e 'import("pkg").then((m) => m.load()).then(console.log)'
foo
Expected
No warning. obuild could add the package's own name to the default externals, along with dependencies and peerDependencies:
...[ctx.pkg.name, ...Object.keys(ctx.pkg.dependencies || {}), ...Object.keys(ctx.pkg.peerDependencies || {})]
.filter(Boolean)
.flatMap((p) => [p, new RegExp(`^${p}/`)]),
Workaround for now: rolldown: { external: [/^pkg(\/|$)/] }.
Versions
- obuild 0.4.40 (latest)
- rolldown 1.2.8
- Node.js 24.20.0
🤖 Generated with AI assistant
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/builders/bundle.ts around lines 93-101, where dependencies and peerDependencies are added to the default externals. Reproduce the issue with the provided package.json, build.config.mjs, and src/index.ts using pnpm obuild; done means self-referencing imports produce no UNRESOLVED_IMPORT warning while the generated import remains external.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100