-
Notifications
You must be signed in to change notification settings - Fork 108
Description
Environment
Node.js: v20.11.0
unbuild: 2.0.0
Reproduction
Lines 129 to 140 in bfb4a34
| await writeFile( | |
| output + ".d.ts", | |
| [ | |
| `export * from ${JSON.stringify(resolvedEntryWithoutExt)};`, | |
| hasDefaultExport | |
| ? `export { default } from ${JSON.stringify( | |
| resolvedEntryWithoutExt, | |
| )};` | |
| : "", | |
| ].join("\n"), | |
| ); | |
Describe the bug
Say I have monorepo entirely build with ESM
Each package is declared as "type": "module" in its package.json
below is the basic directory structure
.
├── apps/
│ └── api/ // ESM module
├── packages/
│ └── db-provider // ESM module
│ ├── dist/
│ │ ├── index.d.ts
│ │ └── ...
│ └── src/
│ └── index.ts
├── package.json
When I execute unbuild --stub in db-provider package, it generates 3 stubbed files in dist/ directory: index.d.ts, index.cjs, index.mjs.
JS files are fine, the problem is index.d.ts
export * from "/Users/yshrsmz/repos/github.com/yshrsmz/sample/packages/db-provider/src/index";In ESM module we need to import files with extension, but there's no extension in the generated code.
And this causes resolution errors in consumer(api) package. (such as Module '"db-provider"' has no exported member 'ConnectionOptions'.).
I looked into the unbuild code and found out it always uses file name without the extension
Lines 129 to 140 in bfb4a34
| await writeFile( | |
| output + ".d.ts", | |
| [ | |
| `export * from ${JSON.stringify(resolvedEntryWithoutExt)};`, | |
| hasDefaultExport | |
| ? `export { default } from ${JSON.stringify( | |
| resolvedEntryWithoutExt, | |
| )};` | |
| : "", | |
| ].join("\n"), | |
| ); | |
btw manually adding .js or .ts temporarily solves the issue
Additional context
No response
Logs
No response