Closed yshrsmz closed 4 weeks ago
My current workaround is to add .js
extension by sed command.
"scripts": {
"stub-fix": "if [[ \"$OSTYPE\" == \"darwin\"* ]]; then pnpm run stub-fix:darwin; else pnpm run stub-fix:linux; fi",
"stub-fix:darwin": "find ./dist -type f -name \"*.ts\" -exec sed -i '' 's/\";$/.js\"/g' {} \\;",
"stub-fix:linux": "find ./dist -type f -name \"*.ts\" -exec sed -i 's/\";$/.js\"/g' {} \\;",
"stub": "unbuild --stub && pnpm run stub-fix",
}
@pi0 Would really like if this problem got resolved; in its current state, I get TS errors either when stubbing, or when building, depending on how I configure my package.json
for packages in the workspace that I link to eachother. The easy stubbing functionality in unbuild
was a really attractive feature when considering using it for our projects.
Environment
Node.js: v20.11.0 unbuild: 2.0.0
Reproduction
https://github.com/unjs/unbuild/blob/bfb4a348421826ad48072ca1cf70973e6caa5b1d/src/builder/rollup.ts#L129-L140
Describe the bug
Say I have monorepo entirely build with ESM Each package is declared as
"type": "module"
in its package.jsonbelow is the basic directory structure
When I execute
unbuild --stub
indb-provider
package, it generates 3 stubbed files indist/
directory:index.d.ts
,index.cjs
,index.mjs
.JS files are fine, the problem is
index.d.ts
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
https://github.com/unjs/unbuild/blob/bfb4a348421826ad48072ca1cf70973e6caa5b1d/src/builder/rollup.ts#L129-L140
btw manually adding
.js
or.ts
temporarily solves the issueAdditional context
No response
Logs
No response