#Unknown file extension .ts

12 messages · Page 1 of 1 (latest)

crisp jackal
#

Hi guys, i have the following configuration, a turborepo project using pnpm and some sveltekit apps, I have a few workspace packages and the all have the same configuration

{
  "name": "@project/package",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "types": "index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

When I import from any of the packages it works as expected, there is no tsconfig.json because it's an internal package and gets packaged with the app, there is one package with the same configuration that I get this error

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/isaac/Desktop/projects/project/packages/formatters/index.ts
     at new NodeError (node:internal/errors:387:5)
     at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:75:11)
     at defaultGetFormat (node:internal/modules/esm/get_format:117:38)
     at defaultLoad (node:internal/modules/esm/load:81:20)
     at nextLoad (node:internal/modules/esm/loader:163:28)
     at ESMLoader.load (node:internal/modules/esm/loader:601:26)
     at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
     at new ModuleJob (node:internal/modules/esm/module_job:63:26)
     at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:476:17)
     at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34)

It only happens for this one package and it happens on every import (so I know I didn't somehow mess up the import) I couldn't find any differences in the packages, it has the same exact structure and since there are no config files I can't think of why it would fail only on this one
It's even weirder because it works on client side navigation only throws an error when visiting a page that uses this package on first load, if I click a link to those pages it loads and the package works

sonic magnet
#

do the import paths have .ts on the end of them in this one package?

crisp jackal
#

no I have checked

#

the error is also weird because it should give me the path to the node-modules folder not the absolute path on my computer

sonic magnet
#

what does the compiled JS look like for whatever file is doing the import of formatters/index.ts?

crisp jackal
#

How do I find the compiled js from sveltekit?

sonic magnet
#

dunno, i've never used sveltekit. often there's a dist/ or lib/ directory that that the compiled output lands in. whatever tooling you use to package up your code for deployment might also have a reference to that path. unless sveltekit is particularly creative with how they handle configuration it should also be in your tsconfig.json file (outDir)

#

i just noticed you have this in your package.json:

"main": "index.ts",

that should almost certainly be referring to a .js file

crisp jackal
#

it is not building within the package so that's why it is a ts main and not a js

sonic magnet
#

sorry, i'm not following

#

i don't think a .ts extension on main will ever work. you're better off just leaving it out if you aren't using it

crisp jackal
#

I don't remember why I added it but it was the only way I could use the package and import properly, anyways I built the application and the error is not happening in the build only when using dev so I guess it's something to do with the way sveltekit handles dev since it seems to not just be compiled ts