To avoid long paths in import
, I'm using Typescript baseUrl
option in my tsconfig.json
Here's my tsconfig.json
:
{
"compilerOptions": {
"target": "ES6",
"module": "none",
"removeComments": true,
"rootDir": "./",
"outDir": "Build",
"moduleResolution": "node",
"noImplicitAny": true,
"pretty": true,
"baseUrl": "./"
},
"exclude": [
"node_modules",
"Build"
]
}
so instead of doing this
import foo from "../../../../hello/foo"
I do this
import foo from "hello/foo"
It's working fine in the Typescript compiler, but when I run my app with node.js, I have this error:
module.js:474
throw err;
^
Error: Cannot find module 'hello/foo'
P.s: I don't want to replace the require()
function like I've seen on the internet
So how can I make node.js working with baseUrl or make typescript replacing paths like "hello/foo"
to "../../../../hello/foo"
?
Typescript compiler version:
Version 2.3.0-dev.20170303
Pass NODE_PATH
env param when you run app with node.js
Example:
set NODE_PATH=./src
node server.js