Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To load an ES module, set "type": "module" in the package.json or use the .mjs extension

I am trying to run on desktop this repository a vscode extension.

I cloned it locally and run npm install

Press f5 on vscode editor and got an error

Process exited with code 1
(node:1404) 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)
internal/process/warning:44
Canceled

To work around with the warning I found another stackoverflow question - (node:9374) Warning: To load an ES module, set "type": "module"

So I set "type":"module" on package.json and press f5 again.

and another error show up.

Process exited with code 1
Uncaught TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /mnt/c/vscode-php-debug/src/phpDebug.ts

And found another question on stackoverflow - Can't run my Node.js Typescript project TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/App.ts

So I remove "type":"module" what happens is I'm in the loop now, confuse.

Does anyone tried debugging this or encounter as such?

like image 581
Fil Avatar asked Dec 01 '20 20:12

Fil


2 Answers

Using the following command worked for me with node v14.16.1:

node --loader ts-node/esm --experimental-specifier-resolution=node index.ts

There is a warning telling me that --experimental-loader is an experimental feature but I don't care because I only use it to debug the typescript code.

like image 143
bfr Avatar answered Sep 20 '22 03:09

bfr


setting "type": "module" in your package.json should work. Check again if you made an error in inputting it. Solved my problem when I inputted it.

like image 36
Afolarin Oyeleke Avatar answered Sep 21 '22 03:09

Afolarin Oyeleke