christian christian - 4 months ago 23
TypeScript Question

TypeScript Compiling Twice when saving .ts files

I am new to typescript and I am running across a problem compiling. So the problem I am having is that when I save my .ts files they are compiled twice and in two different locations.

My current file structure is:

-app

|-css (all css files)

|-html (all html files)

|-js (all js files)

|-ts (all ts files)


When I save my .ts files they are compiled and placed in the js folder but then a set of new folders is created in the format:

-app

|-...

|-js (all js files)

|-app

|-ts (all js files [that were saved ts files])
|-...


I have been looking around for anyone with a similar problem but couldn't find anything. My package.json file and tsconfig.json files are as follows:

package.json

{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/forms": "0.2.0",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "3.0.0-beta.1",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.4",
"angular2-in-memory-web-api": "0.0.14",
"bootstrap": "^3.3.6",
"core-js": "^2.4.0",
"d3": "^4.1.1",
"d3tip": "0.5.0",
"d3-tip": "0.6.7",
"d3-tooltip": "0.0.1",
"moment": "^2.14.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "0.19.27",
"zone.js": "^0.6.12"
},
"devDependencies": {
"concurrently": "^2.0.0",
"lite-server": "^2.2.0",
"typescript": "^1.8.10",
"typings": "^1.0.4"
}
}


tsconfig.json:

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "app/js",
"rootDir": "app/ts"
}
}


UPDATE: Still having this problem. --Not Resolved --07/28/2016--

Answer

Okay, so I thought a few weeks back that I solved this issue but I was wrong. HOWEVER, I have now found the solution.

The problem was actually not with the location of where my js files were being compiled. The js files were going to the correct location during the first compile, BUT I am using the Atom IDE and atom-typescript has a default that it compiles the files when they are saved in the Atom-editor. Hence, Atom was compiling the files a second time, every time I saved a file.

THE FIX: (tell atom-typescript to not compile)

change tsconfig.json to:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "./app/js"
  },
  "compileOnSave": false
}

all we did was add the "compileOnSave" option and set it to false. Thus telling the atom compiler to not compile when saved.

NOTE** the files are still compiled on change due to tsc running concurrently with my lite-server.

Comments