无法使用 tsc 节点模块编译打字稿 [英] Cannot compile typescript using tsc node module

查看:94
本文介绍了无法使用 tsc 节点模块编译打字稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 tsc 节点包模块将打字稿编译为 JavaScript.首先,我使用 npm install -g typescript 安装了模块.在我的本地目录中,我创建了一个名为 classes.js 的文件,其中包含有效的打字稿代码.运行 tsc classes.js 时出现以下错误:Error reading file "./classes.js": File not found

I'm trying to compile a typescript into JavaScript using tsc node package module. First of all, I've installed the module using npm install -g typescript. In my local directory I've created a file called classes.js containing a valid typescript code. When running tsc classes.js I get the following error: Error reading file "./classes.js": File not found

该错误没有多大意义,因为文件存在.使用绝对文件路径时显示相同的错误.我想知道 tsc 模块是否有问题,还是我遗漏了什么?

The error doesn't make much sense, since the file exist. Same error is shown when the absolute file path is used. I'm wondering if there is something wrong with tsc module or am I missing something?

推荐答案

打字稿编译器专门查找扩展名 .str.ts.这是解析输入文件名的代码:

The typescript compiler specifically looks for extensions .str and .ts. Here is the code that resolves input file names:

if(!TypeScript.isSTRFile(normalizedPath) && !TypeScript.isTSFile(normalizedPath)) {
    normalizedPath += ".ts";
}  

然后编译器会查找名为 normalizedPath 的文件,在您的情况下,该文件对应于不存在的 classes.js.ts.在我看来,编译器应该在这里输出更好的错误信息.

The compiler then looks for a file with name normalizedPath, which in your case corresponds to classes.js.ts, which does not exist. In my opinion, the compiler should output a better error message here.

这篇关于无法使用 tsc 节点模块编译打字稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆