content-collections icon indicating copy to clipboard operation
content-collections copied to clipboard

Issue on static import Tanstack start

Open tecoad opened this issue 3 months ago • 1 comments

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?

tecoad avatar Sep 26 '25 16:09 tecoad

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.

sdorra avatar Sep 26 '25 20:09 sdorra