0

So I have this really neat project with some really neat debugging which has worked since forever but after a too long hiatus and now I can't seem to get it to work. Like I noticed this in the debug tab

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/inaba/Programming/Lewd/packages/main-site/src/index.js:1
import express from "express";

Here's my launch.json, which has worked for like forever

{
  "type": "node",
  "request": "launch",
  "name": "Launch Main App",
  "preLaunchTask": "npm: build",
  "program": "src/index.js",
  "sourceMaps": true,
  "outFiles": [
    "dist/**/*.js"
  ],
  "envFile": "${workspaceFolder}/../../.env",
  "runtimeArgs": [
    "--require=dotenv/config"
  ]
}

So what the heck? As far as I can tell I'm doing things right?

Ja Da
  • 230
  • 2
  • 12

2 Answers2

1

If you want to use that --trace-warnings in vscode debug, just add it into runtimeArgs.

don't forget to stop the debugging session if it is running

{
  "type": "node",
  "request": "launch",
  "name": "Launch Main App",
  "preLaunchTask": "npm: build",
  "program": "src/index.js",
  "sourceMaps": true,
  "outFiles": [
    "dist/**/*.js"
  ],
  "envFile": "${workspaceFolder}/../../.env",
  "runtimeArgs": [
    "--require=dotenv/config",
    "--trace-warnings"
  ]
}
Windo
  • 1,526
  • 1
  • 12
  • 8
0

Try require() instead of the import statement

Citing Node documentation here:

import statements are permitted only in ES modules. For similar functionality in CommonJS, see import().

https://nodejs.org/api/esm.html#esm_import_statements

Some detailed context here: Using Node.js require vs. ES6 import/export

Dumi Jay
  • 1,057
  • 10
  • 10