使用Node.js打印baseUrl
为了避免import
长path,我在我的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'
Ps:我不想要像在互联网上看到的那样replacerequire()
函数
那么我怎样才能让node.js和baseUrl一起工作,或者把打字机replace成"hello/foo"
到"../../../../hello/foo"
?
Typescript编译器版本:
Version 2.3.0-dev.20170303
当您使用node.js运行应用程序时,传递NODE_PATH
env参数
例:
set NODE_PATH=./src node server.js