content-collections
content-collections copied to clipboard
Issue on static import Tanstack start
Hi, On my Tanstack start project, i am trying to do this, pretty much as documented:
transform: async (document, context) => {
const component = createDefaultImport<React.ComponentType>(`@/components/${document.component}`)
return {
...document,
component,
}
},
However, this gives me:
An error occured while server rendering /lab-1: Cannot find module '@/components/Lab1' imported from '/Users/matheus/project/.content-collections/generated/allLabs.js'
My tsconfig:
"paths": {
"@/*": [
"./src/*"
],
"content-collections": [
"./.content-collections/generated"
]
},
Seems that Content-collections is not able to sort @ path, from the tsconfig. Is this approach correct?
Ok, I can reproduce it. The problem seems to be that the alias is used in a .js file instead of a .ts file. You can solve this by using resolve in the vite.config.ts:
resolve: {
alias: {
"@": "/src",
},
},
I'm not sure why viteTsConfigPaths does not work in this case.