bug: Unknown file extension `.json` in 6.x
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 275
- PR merge metrics
- No merged PRs in 30d
Description
Hi, thank you for the library.
I came into an issue while updating to version 6.
Code (`index.ts`)
```
const dir = './xyz'
const realPath = relative(
__dirname,
fs.realpathSync(join(dir, 'file.json'))
)
const { default: content } = await import(realPath)
console.log(content)
```
Working fine
- Version `5.x` (latest 5.12.9)
- Build command `tsup src/index.ts --format esm,cjs --dts`
With version `6.x` after reading release notes I though, that I need to add `--shims` (not mentioned in docs, only on release page) to build command (because we are using `__dirname`). Unfortunately that is not the case.
Does not work fine
- Version `6.x` (any version)
- Build command `tsup src/index.ts --shims --format esm,cjs --dts`
Issue on version `6.x`
```
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".json" for /Users/***********/xyz/file.json
at new NodeError (node:internal/errors:371:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:87:11)
at defaultGetFormat (node:internal/modules/esm/get_format:102:38)
at defaultLoad (node:internal/modules/esm/load:21:14)
at ESMLoader.load (node:internal/modules/esm/loader:359:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:58)
at new ModuleJob (node:internal/modules/esm/module_job:66:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:297:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:261:34)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
```
Is there any way of fixing this?
Contributor guide
Assessment
This issue has not been assessed yet.