Typescript baseUrl with Node.js
As @jez said you need to set the NODEPATH when running the node app. This is configuration may help you:
tsconfig.json
"outDir": "dist",
"baseUrl": "./",
Package.json
"scripts": {
"build": "tsc",
"dev": "NODE_PATH=./ ts-node ./src/index.ts",
"start": "NODE_PATH=./dist node ./dist/index.js",
"prod": "npm run build && npm run start"
},
Windows users might want to use cross-env with above mentioned answers.
package.json
"scripts": {
"dev": "cross-env NODE_PATH=./ ts-node ./src/index.ts"
}
Pass NODE_PATH
env param when you run app with node.js
Example:
set NODE_PATH=./src
node server.js