Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 98506

Using "esm" in VSCode's NodeJs Debugger

$
0
0

I am using Vscode.

I have a js file filled with a dozen+ class definitions which I wanted to be available in another jsfile. So I used es6 imports in my other file, main.js

//main.js
import * as Helper from './helperClasses.js';
var myDoggy = new Helper.Pet("Fido");

But that wouldn't run with node, so I installed 'esm' with npm, and made a file called server.js, in which I added

//server.js
require = require("esm")(module/*, options*/)
module.exports = require("./main.js")

Now that runs with the code runner extension, or from a cmd window with the '-r esm' args (i.e. node -r esm server.js). But in the vsCode debugger, I get the following error:

import * as helper from './helperClasses.js';
       ^

SyntaxError: Unexpected token *

I tried changing the configuration settings in launch.json as follows, but that did not work:

"configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}\\game.js",
            "args": ["-r","esm","server.js"]
        }
    ]

I went and changed the .js extensions to .mjs, but then intellisense stopped working...

Is there something I'm missing? This is my first time trying to use Node and I'm just trying to easily import some helper functions.


Viewing all articles
Browse latest Browse all 98506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>