Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running babel-node in visual studio code

Normally to start up via command line, I can type:

babel-node server.js

When I try to set this up so that breakpoints and what not work in visual studio code I receive:

/Users/me/proj/node_modules/babel-cli/lib/babel-node.js --debug-brk=31893 --nolazy server.js 
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 1: /Applications: is a directory
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 3: /Applications: is a directory
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 4: Dockerfile: command not found
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: syntax error near unexpected token `('
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: ` * when found, before invoking the "real" _babel-node(1) executable.'

I surmise it has to do with the fact that the executable is being called from that directory, rather than from the same directory as the server.js file - but I really don't know.

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/server.js",
            "stopOnEntry": false,
            "args": [],
            "cwd": "${workspaceRoot}",
            "preLaunchTask": null,
            "runtimeExecutable": "${workspaceRoot}/node_modules/babel-cli/lib/babel-node.js",
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "externalConsole": false,
            "sourceMaps": false,
            "outDir": null
        },
        {
            "name": "Attach",
            "type": "node",
            "request": "attach",
            "port": 5858,
            "address": "localhost",
            "restart": false,
            "sourceMaps": false,
            "outDir": null,
            "localRoot": "${workspaceRoot}",
            "remoteRoot": null
        }
    ]
}
like image 803
Prescott Avatar asked Mar 13 '16 20:03

Prescott


People also ask

How do I run a Node in VSCode?

Open integrated terminal on visual studio code ( View > Integrated Terminal ) type 'node filename. js' press enter.

How do I run Node in Visual Studio?

In Visual Studio, go to Tools > Get Tools and Features. In the Visual Studio Installer, select the Node. js development workload, and select Modify to download and install the workload.


1 Answers

The error occurs because the babel-node.js file is not the babel-node executable but a wrapper file that adds node flags:

babel-node.js

/* eslint indent: 0 */

/**
 * This tiny wrapper file checks for known node flags and appends them
 * when found, before invoking the "real" _babel-node(1) executable.
 */

To fix this, the location of the babel-node binary should be set as the value of the runtimeExecutable property. The location is:

"${workspaceRoot}/node_modules/.bin/babel-node"
like image 102
gnerkus Avatar answered Sep 24 '22 12:09

gnerkus