Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outDir and rootDir does not work for tests or debugging of TypeScript #1243

Closed
lostfields opened this issue Aug 31, 2016 · 9 comments
Closed

outDir and rootDir does not work for tests or debugging of TypeScript #1243

lostfields opened this issue Aug 31, 2016 · 9 comments

Comments

@lostfields
Copy link

@lostfields lostfields commented Aug 31, 2016

Expected Behavior

Debugging of TypeScript should work with outDir + rootDir in tsconfig

Actual Behavior

Throws an error complaining that corresponding javascript file isn't found

  • NTVS Version: 1.2.40627.01
  • Visual Studio Version: 14.0.25422.01 Update 3
  • Node.js Version: 6.3.0
Steps to Reproduce
  1. Create a "Blank NodeJS Console Application"
  2. Move "app.ts" into folder "src"
  3. Add "tsconfig.json"
{
    "compilerOptions": {
        "target": "ES6",
        "module": "commonjs",
        "declaration": true,
        "sourceMap": true,
        "outDir": "./build",
        "rootDir": "./src"
    },
    "exclude": [
        "build"
    ]
}
  1. Set a break-point in app.ts
  2. Start debugger and an error is thrown. Notice that outDir and rootDir isn't respected.
Debugger listening on [::]:5858
 module.js:442
    throw err;
    ^

Error: Cannot find module '[project-path]\src\app.js'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Timeout.Module.runMain [as _onTimeout] (module.js:575:10)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
 Press any key to continue...
  1. Disable tsconfig.json for a bit, and open "Project properties", and set outputdir to "./build" and root dir to "./src".
  2. Re-enable tsconfig.json
  3. Debug again and an error is thrown. Now is outDir respected, but debugger does not know of our rootDir as it looking for \build\src\app.js and not \build\app.js
Debugger listening on [::]:5858
 module.js:442
    throw err;
    ^

Error: Cannot find module '[project-path]\build\src\app.js'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Timeout.Module.runMain [as _onTimeout] (module.js:575:10)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
 Press any key to continue...
@mjbvz
Copy link
Contributor

@mjbvz mjbvz commented Sep 1, 2016

@lostfields
Thank you for reporting this.

It looks we do not properly pick up typescript project properties in the case where a tsconfig.json file exists. When getting the name of the js file to launch, TypeScriptOutDir always returns null (unless it has been previously set, but this function will still not return the value from the tsconfig.json ever): https://github.com/Microsoft/nodejstools/blob/86327f9bf3ce5789bc2ed4f1923dee21e06623d0/Nodejs/Product/TypeScript/TypeScriptHelpers.cs#L37

We have the same core problem rootDir, but I don't think we support rootDir at all right now. The MsBuild property is TypeScriptSourceRoot I believe

@billti, @Jasonra
For Typescript, since the tsconfig.json file appears to be the source of truth for Typescript projects, is there any way to access project properties that file defines from the NTVS extension? I'd like to avoid adding custom logic to parse and understand tsconfig.json files on our side if possible.

@lostfields
Copy link
Author

@lostfields lostfields commented Sep 1, 2016

I really hope this get fixed soon as this makes my npm packages a lot cleaner and a lot nicer when referencing sub modules. If I'm naming outDir 'lib' instead it will be like 'import .... from "my-npm-package/lib/app"'. Looks a lot nicer than typing 'my-npm-package/lib/src/app'.

@lostfields
Copy link
Author

@lostfields lostfields commented Sep 1, 2016

I think this is related to #1241 where Test Explorer/Mocha can't discover the tests.

@ZenSoftware
Copy link

@ZenSoftware ZenSoftware commented Nov 10, 2016

I am experiencing this particular bug as well. outDir and rootDir within tsconfig.json are not being respected when launching the debugger in VS Enterprise 2015. VS will try to launch a non-existent script. Specifically it tries to execute the transpiled "Node.js Startup File" in the path that is directly adjacent to the source, instead of in the outDir. I'm not too sure how to correct this.

@lostfields
Copy link
Author

@lostfields lostfields commented Nov 10, 2016

@ZenSoftware for now, disable tsconfig and try to apply the same settings to "Project > Properties" under "TypeScript Build" and then enable your tsconfig again.

@lostfields
Copy link
Author

@lostfields lostfields commented Apr 24, 2017

Ahhh.... please fix this for Visual Studio 2017 with inbuilt typescript. Where do I report that

@lostfields
Copy link
Author

@lostfields lostfields commented Dec 13, 2017

still not fixed :-(

@paulvanbrenk
Copy link
Contributor

@paulvanbrenk paulvanbrenk commented May 2, 2018

This looks like it's much more work than I expected. Closing in favor for #1949 which captures more use cases.

@KhoiNguyenICT
Copy link

@KhoiNguyenICT KhoiNguyenICT commented Nov 6, 2018

Can't you help me fix this ?. I change outDir but my vs push notification program can't not file app.js in source dist '.'. Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants