Mixed output slashes - Cannot find module './src\util\getSomething'
inspiraller opened this issue · 1 comments
inspiraller commented
Please advise if doing this right?
tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"allowJs": false,
"strict": true,
"target": "es6",
"module": "commonjs",
"lib": ["dom", "es6", "es5", "es2017", "esnext.asynciterable"],
"sourceMap": true,
"moduleResolution": "node",
"paths": {
"src/*": ["src/*"]
},
"declaration": true,
"rootDir": "./src",
"outDir": "dist"
},
"exclude": ["dist"],
"include": [ "src"]
}
Original Folder structure
src /
util/
getSomething.ts
index.ts
Output Folder structure
dist /
util/
getSomething.js
index.js
index.ts
import getSomething from 'src/util/getSomething';
package.json script
{
"build": "tsc && tspath -f",
"start": "node dist/index.js"
}
The build works but when I run start I get error.
Note: I am using windows.
npm start
Error: Cannot find module './src\util\getSomething'
Require stack:
c:\apps\example-typescript-node\dist\index.js
inspiraller commented
I have resolved my problem. I had to ensure my rootDir was ./ not src.
Then targeting index.js inside dist/src/ not dist/
tsconfig.json
{
"compilerOptions": {
"rootDir": "./"
}
}
package.json
{
"build": "tsc && tspath -f",
"start": "node dist/src/index.js"
}