nksaraf / vinxi

The Full Stack JavaScript SDK
https://vinxi.vercel.app
MIT License
1.91k stars 77 forks source link

Loading ts file via subpath export in app.config.ts in >0.3.4 doesn't work #259

Open Brendonovich opened 6 months ago

Brendonovich commented 6 months ago

In v0.3.5 and greater, using a subpath export from a monorepo package that points to a .ts file fails with the following error:

node:internal/modules/esm/get_format:160
  throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath);
        ^

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/brendonovich/github.com/mattrax/mattrax/apps/forge/app.config.timestamp_1710758212592.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:143:22)
    at async ModuleLoader.load (node:internal/modules/esm/loader:409:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45)
    at async link (node:internal/modules/esm/module_job:76:21) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

I expect this is because 0.3.5 changed the loading of app.config.ts from using a dynamic import() to dedicated bundling with esbuild.

Here's a repro of the error occurring. Downgrading vinxi to =0.3.4 and running pnpm install results in the config loading properly.

edivados commented 2 months ago

It's probably because 0.3.4 used c12 / jiti. Right now your package is being externalized. I vaguely remember there being issues with jiti and yarn but I don't know the reason why it's not being used anymore.