module-builder
module-builder copied to clipboard
Type import invalid path in build
Description
Types imported from parent folders have incorrect import paths and do not get recognized by TS due to the incorrect .js extension
Expected Behavior
Type import paths should end with .mts
Reproduction
https://codesandbox.io/p/devbox/l8c85t?file=%2Fdist%2Fruntime%2Futils%2Ffoo.d.ts%3A3%2C1
See the build output in dist. Type Foo imported from src/types.ts in the file src/runtime/server/utils/foo.ts using this import statement import type { Foo } from "../../../types";, got transformed to ../../../types.js which does not have a declaration file, and produces incorrect type.
Workaround
This is how I currently work around this issue.
import fs from 'node:fs'
import path from 'node:path'
export default defineBuildConfig({
hooks: {
'rollup:done': function (ctx) {
const dts = path.resolve(ctx.options.outDir, 'types.d.mts')
if (fs.existsSync(dts))
fs.cpSync(dts, path.resolve(ctx.options.outDir, 'types.d.ts'))
},
},
})
Related Issue
#308 seems relevant, but I don't know how it's fixed for them