Gerald Gerald - 9 months ago 40
Node.js Question

Compiling TypeScript to JavaScript using Visual Studio Code

I am new to NodeJS and TypeScript and I want to begin by setting up my project folder. I already have my tsconfig.json

{
"compilerOptions": {
"outDir": "./build",
"module": "commonjs",
"target": "es5",
"noImplicitAny" : false
},
"files": [
"./src/**/*.ts"
],
"exclude": [
"node_modules"
]}


and package.json

{
"name": "crm",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}


This is my simple directory structure:

crm/
|-src/
|- main/
|- app.ts


when I compile it using the tsc command, I expected that the compiled directory will be

crm/
|-build/
|- main/
|- app.js

|- src/
|- main/
|- app.ts


but the result is

crm
|- build/
|- app.js

|- src/
|- main/
|- app.ts


there is no main folder that is created.

I dont know if the problem is on tsconfig.json or in the tsc command

Answer Source

You have set

"outDir": "./build",

in your tsconfig.json and no rootDir. Check compilerOptions here

Set the required output build path.

"outDir": "./build",
"rootDir": "./src"

You will get

crm
 |- build/
    |- main/
       |- app.js

Src: this issue