21

I have a few typescript files for my app myapp in my Visual Studio 2017 ASP.NET project. I use a gulp task to generate the JS files, so I don't want the build or language service creating these JS and JS.MAP files.

This is how my TSCONFIG file look like:

{
  "compileOnSave": false,
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "module": "system",
    "types": [ "" ],
    "lib": [
      "es6",
      "dom"
    ]
  },
  "include": [
    "./myapp/**/*"
  ]
}

I tried the following:

  1. I added the myapp to the exclude section of the tsconfig.js. Both the js and js.map are not generated at that time if I close Visual Studio and open again. But I see a lot of compilation errors.

  2. I added <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> to the .csproj file. I closed VS 2017, opened again and did a build. I see the JS and JS.MAP files.

  3. I changed the BuildAction property to none, but still see the JS and JS.MAP files

enter image description here

What should I do so the syntax check of the TS file will work but does not generate any JS and JS.MAP files?

5
  • Possible duplicate of How to prevent visual studio 2017 from build javascript? Commented Aug 28, 2017 at 13:39
  • 2
    The issue I have is different. I don't do a build option from the menu from Visual Studion. I just close and open the project and start seeing these behaviors. Commented Aug 28, 2017 at 15:08
  • I know this is a bit old, but if your problem is mainly the js.map, you can just set sourceMap to false on tsconfig Commented Dec 3, 2018 at 17:38
  • 2
    @wonderfulworld Did you found any solution? Commented Mar 7, 2019 at 16:43
  • @wonderfulworld your VS is actually running TSC command each time to check for TS errors (it reads tsconfig.json) which without "noEmit": true will output JS files to your folder... Commented Sep 2, 2020 at 11:26

5 Answers 5

16

Try add "noEmit": true in your tsconfig. It should prevent the .js .js.map from generating.

Sign up to request clarification or add additional context in comments.

3 Comments

This doesn't work for me, do you know of any reason why this would be the case?
@ChristopherThomas Check your typescript version, if it's older than 4.0 then there's a flag called "incremental": true that confict with "noEmit": true
also works in VS Code
5

Try add "noEmitOnError": true in your tsconfig. It should prevent the .js .js.map from generating if there is any error in the TS files(s).

Comments

3

If Visual Studio seems to be ignoring the noemit option in the tsconfig file, edit your project file. In the project file, go to the <PropertyGroup> that contains the rest of the TypeScript options and add <TypeScriptNoEmit>True</TypeScriptNoEmit> between that PropertyGroup's open and closing tags.

2 Comments

This one did it for me. NOTE: You may need to restart VS after changing the project file for the changes to take effect.
works in VS2022 without restart (just reload project), thanks
1

I noticed that if I created the file using angular it didn't emit a .js but if I added a new TypeScript file from Visual Studio via the New Item menu it did. Turns out the latter sets the Build Action to "TypeScript file" whereas the former sets the build action to None, Do Not Copy. I changed the offending TypeScript files to None and it's stopped the .js files being generated. This is contrary to the OPs statement that it had no affect - but in my case it worked. Setting noEmit: true just resulted in no vendor.js file being generated for my angular ng build.

Comments

0

My issue was I had accidentally deleted "outDir" from my tsconfig.json.

To fix, I added the line back in:

{
  "compilerOptions": {
    ...
    "outDir": "./dist",
    ...
  }
}

From the Typescript Docs - Out Dir:

If specified, .js (as well as .d.ts, .js.map, etc.) files will be emitted into this directory. The directory structure of the original source files is preserved; see rootDir if the computed root is not what you intended.

If not specified, .js files will be emitted in the same directory as the .ts files they were generated from

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.