Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript moduleResolution是节点,但编译时和运行时不同_Typescript - Fatal编程技术网

Typescript moduleResolution是节点,但编译时和运行时不同

Typescript moduleResolution是节点,但编译时和运行时不同,typescript,Typescript,我有一个Node Express项目,我的模块解决方案设置为节点。tsc能够无错误地解决和编译以下问题: app.ts包含: import { HttpError} from "myTypes"; export class HttpError { statusCode: number; message: string; constructor(status?: number, msg?: string) { this.statusCode = status; thi

我有一个Node Express项目,我的
模块解决方案
设置为
节点
。tsc能够无错误地解决和编译以下问题:

app.ts
包含:

import { HttpError} from "myTypes";
export class HttpError {
  statusCode: number;
  message: string;
  constructor(status?: number, msg?: string) {
    this.statusCode = status;
    this.message = msg;
 }
tsconfig.js
具有:

"paths": {
        "*": [
            "node_modules/*",
            "src/types/*"
        ]
    }
文件夹结构为:

/src---types
  |      |--myTypes.ts
  |
  |----app.ts
outDir
文件夹在同一层次结构中具有相同的
types
文件夹,并且
myTypes.js
文件在其中

但是,在运行时,我遇到了一个
找不到模块“myTypes”的错误。为什么会这样

PS:我希望使用非相对模块导入。如果我只使用“/types/myTypes”中的
import{HttpError},效果很好。但我想理解为什么上述方法不起作用


myTypes.ts
包含:

import { HttpError} from "myTypes";
export class HttpError {
  statusCode: number;
  message: string;
  constructor(status?: number, msg?: string) {
    this.statusCode = status;
    this.message = msg;
 }

}

myTypes到底是什么?HttpError是如何使用的?myTypes只包含一个导出的类。我把它加进去了。我明白了。因此,导入是真实的,而不仅仅是一种类型。路径不会影响运行时。看见我建议使用与在原始节点中相同的方法。