Node.js: How to use npm ES6 modules (import) in commonjs (require) app.js

Viewed 424

I'm kind of a newbie with node.js, so please, be merciful :)

I use node ver 14.15.1 The problem I'm facing is to get a npm module("ghost-cursor", https://www.npmjs.com/package/ghost-cursor) that is written in ES6 ("import") working in commonjs (require). I need to pack my node.js app in an exe file and the npm "pkg" doesn't seem to work with ES6. With nexe I can't get to pack all dependencies in order to work outside of the project folder and on other machines... I have tried to transpile the ES6 module to commonjs with babel:

babel --presets=es2015 ./folder/filename.js > ./folder/filenameCJ.js

but I get the error: SyntaxError: Invalid or unexpected token

I have also tried the solutions posted in: How to use ES6 modules in CommonJS?

but I can't get it to work.

Are there any other ways, except "nexe" and "pkg" to make an exe file from node.js? Is it possible to use an ES6 module from npm in commonjs with require? If so, how?

Thanky you for your help and replies.

0 Answers
Related