GoogleFeud / ts-runtime-checks

A typescript transformer that automatically generates validation code from your types.
https://googlefeud.github.io/ts-runtime-checks/
MIT License
312 stars 7 forks source link

[BUG] Generated import for a custom error does not work in ESM mode #53

Closed FredTreg closed 6 months ago

FredTreg commented 7 months ago

Describe the bug This is a follow-up of https://github.com/GoogleFeud/ts-runtime-checks/issues/47

ts-runtime-checks now properly generates an import statement for custom errors but does not generate the required .js extension when the project is in ESM mode (i.e. "type": "module")

The generated code then fails with:

node:internal/modules/esm/resolve:255
     throw new ERR_MODULE_NOT_FOUND(
           ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/server/dist/utils/errors' imported from /server/dist/modules/trails/trail.controller.js

Expected behavior For a project with "type": "module" defined in its package.json file, the following code should be generated:

import { InputError } from "../../utils/errors.js";

for now the following is generated (no .js extension):

import { InputError } from "../../utils/errors";

Additional context