Search code examples
node.jstypescriptimportmodulets-node

Typescript import .ts files runtime error when trying to run the application using `ts-node-esm`


I use Node.JS workspace with the following structure:

root/
    |- build/
    |- ModuleA/
         |- build/
    |- ModuleB/
         |- build/
    |- WebAPI/
         |- build/
         |- server.ts

Running the app with ts-node-esm src/webapi/server.ts bumps into the following error:

CustomError: Cannot find module '/root/webapi/Presenters/RegisterUserPresenter'

on the line of import:

import { RegisterUserPresenter } from "../Presenters/RegisterUserPresenter"

Solution

  • node --experimental-specifier-resolution=node build/src/webapi/server.js does the job!