[英]Node.js Typescript import local files, module not found
I compile Typescript to a compile directory called lib
我将 Typescript 编译到名为
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.当我从 typescript 文件导入本地文件时,相对路径不适用于编译的
.js
文件,因为它们被编译到不同的目录中。
Hence it throws Error: Cannot find module './email/test.mjml'
Error因此它抛出
Error: Cannot find module './email/test.mjml'
错误
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?
有没有办法配置它以在编译时修复导入路径?
tsc
has no option to copy non TS files. tsc
没有复制非 TS 文件的选项。 One solution is to use copyfiles
as part of your build.一种解决方案是使用
copyfiles
作为构建的一部分。
Check out this blog post for more info.查看此博客文章了解更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.