【发布时间】:2017-07-23 19:05:24
【问题描述】:
为了避免 import 中的长路径,我在 tsconfig.json 中使用 Typescript baseUrl 选项
这是我的tsconfig.json:
{
"compilerOptions": {
"target": "ES6",
"module": "none",
"removeComments": true,
"rootDir": "./",
"outDir": "Build",
"moduleResolution": "node",
"noImplicitAny": true,
"pretty": true,
"baseUrl": "./"
},
"exclude": [
"node_modules",
"Build"
]
}
所以不要这样做
import foo from "../../../../hello/foo"
我这样做
import foo from "hello/foo"
它在 Typescript 编译器中运行良好,但是当我使用 node.js 运行我的应用程序时,出现以下错误:
module.js:474
throw err;
^
Error: Cannot find module 'hello/foo'
P.s:我不想像在网上看到的那样替换require()函数
那么我怎样才能让 node.js 与 baseUrl 一起工作,或者让 typescript 替换像 "hello/foo" 到 "../../../../hello/foo" 这样的路径?
Typescript 编译器版本:
Version 2.3.0-dev.20170303
【问题讨论】:
标签: node.js typescript