Type generation is broken for subfolders (subfolder is imported with .js extension)
Reproduction
Build command: cd ~/projects/vitejs-vite-tu4fsx/my-module/ && npm run dev:build && npm run prepack
Describe the bug
After upgrading from 0.5.5 to 0.8.0 the generated bundle has invalid import paths for types that exist in subfolders.
We have e.g. the following structure in our nuxt module runtime/ folder:
src/
runtime/
types/
index.ts (export * from './components')
components/
index.ts (export * from './Alert')
Alert.ts
Which results in the following build:
dist/
runtime/
types/
index.d.ts (export * from './components.js')
components/
index.d.ts (export * from './Alert.js')
Alert.d.ts
Alert.js
Where the path ./components.js is invalid. It should be: ./components.
I am also unsure whether components/index.d.ts in the build should export ./Alert.js or Alert.d.ts.
I'll fix this, but you should probably do from './components/index' anyway. (And this should probably resolve the issue for now.)
I'll fix this, but you should probably do
from './components/index'anyway. (And this should probably resolve the issue for now.)
Thank you for the quick reply and the great work on nuxt! :)
I hadn't thought about referencing the index file directly - I tested it and it does indeed fix the type referencing.
Appreciate the help :+1:
I think fixing this issue or at least logging some warnings when importing from a folder index (without filename) will probably save us a lot of time debugging type issues in the future 😅
Not sure where to start to work on a fix 😥
Was just looking at this. I think maybe issue is upstream in mkdist.