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

node script file that extension name is '.njs' can't be debug,throw err:Cannot launch program setting the 'outFiles' attribute might help #33051

Closed
purplestone opened this issue Aug 24, 2017 · 8 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@purplestone
Copy link

purplestone commented Aug 24, 2017

  • VSCode 1.15.1
  • OS win7 x64
  • Shell 1.6.6
  • Render 56.0.2924.87
  • Nodejs 7.4.0

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${file}"
        }
    ]
}

Create a file name : go.njs:

debugger;
console.log();

press F5 to debug throw: Cannot launch program ”xxx\js\go.njs“ setting the 'outFiles' attribute might help

But I rename that file extension name '.njs' to '.js', It works well.

@vscodebot vscodebot bot added the debug Debug viewlet, configurations, breakpoints, adapter issues label Aug 24, 2017
@purplestone purplestone changed the title node script file of extension name is '.njs' can't be debug,throw err:Cannot launch program setting the 'outFiles' attribute might help node script file that extension name is '.njs' can't be debug,throw err:Cannot launch program setting the 'outFiles' attribute might help Aug 24, 2017
@weinand
Copy link
Contributor

weinand commented Aug 24, 2017

I've never heard of a file extension "njs".
Can you point me to a definition?

@weinand weinand added the info-needed Issue requires more information from poster label Aug 24, 2017
@purplestone
Copy link
Author

purplestone commented Aug 24, 2017

In /Microsoft VS Code/resources/app/extensions/javascript/package.json
the js file extensions can be name:
"extensions": [
".js",
".es6",
".jsx",
".mjs"
],

So I name my node script files to '*.njs',

The above extension names will throw err except '.js'
IDE should not restrict my script file extension name, I had specified execute type of script file ("type": "node")

@weinand weinand added feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels Aug 24, 2017
@weinand weinand added this to the Backlog milestone Aug 24, 2017
@MikeRalphson
Copy link

@purplestone note above the list of extensions includes .mjs not .njs (em, not en).

I'm not sure if renaming your module to .mjs will fix the debugger issue though, as I am getting the same error trying to debug a .mjs module in Node 9 nightly using the --experimental-modules runtimeArgs.

@MikeRalphson
Copy link

@weinand this looks to be an issue in https://github.com/microsoft/vscode-node-debug2

The javascript debugger only wants to debug files where

            if (utils.isJavaScript(programPath)) {

is true. See line 467

This test is only satisfied if the programPath ends with .js or there is a specific node shebang string at the top of the file:

const NODE_SHEBANG_MATCHER = new RegExp('#! */usr/bin/env +node');
//...
if (name.endsWith('.js')) {
        return true;
}
//...
if (NODE_SHEBANG_MATCHER.test(line)) {

Adding

#!/usr/bin/env node

to the top of the affected .mjs file allows it to be debugged.

The assumption seems to be that .mjs files will always generate .js source files (i.e. via babel etc), but this assumption is no longer true with native .mjs support in recent Node.js builds (even if this is currently behind a flag).

@JoseBalado
Copy link

JoseBalado commented Sep 28, 2017

Hi, I can not debug node.js modules with the .mjs extension unless I add #!/usr/bin/env node to the top of the module.
Tested with Node v8.5.0 and v8.6.0 using --experimental-modules flag.

Thanks for your solution @MikeRalphson

SindreSvendby added a commit to SindreSvendby/vscode-node-debug2 that referenced this issue Oct 8, 2017
Fix for not beeing able to debug a ,mjs file in Code. See 
microsoft/vscode#33051 for more details.
SindreSvendby added a commit to SindreSvendby/vscode-node-debug that referenced this issue Oct 9, 2017
Fix for not beeing able to debug a `.mjs` file in Code. See 
microsoft/vscode#33051 for more details.
@weinand weinand modified the milestones: Backlog, November 2017 Nov 14, 2017
@weinand
Copy link
Contributor

weinand commented Nov 14, 2017

I've added the extensions ".js", ".es6", ".jsx", ".mjs" to the list of recognised JavaScript extensions.

@weinand weinand added the verification-needed Verification of issue is requested label Dec 4, 2017
@weinand
Copy link
Contributor

weinand commented Dec 5, 2017

Verify that you can debug a JavaScript program if the file extension is ".es6", ".jsx", ".mjs".

@JoseBalado
Copy link

JoseBalado commented Dec 5, 2017

@weinand It works with ".mjs" extension.
Thanks

@weinand weinand added the verified Verification succeeded label Dec 5, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

4 participants