Node.js Typescript import local files, module not found

Viewed 19

I compile Typescript to a compile directory called lib

And when I import local files from my typescript file, the relative path won't work for the compiled .js files, since they are compiled into different directory.

Hence it throws Error: Cannot find module './email/test.mjml' Error

const text = require("./mytext.txt");

How can this be fixed? Is there a way to configure it to fix the import paths when it compiles?

1 Answers

tsc has no option to copy non TS files. One solution is to use copyfiles as part of your build.

Check out this blog post for more info.

Related