bytenode: SyntaxError: Unexpected identifier

I used bytenode -c index.js , the following error occurred:

evalmachine.<anonymous>:1 (function (exports, require, module, __filename, __dirname) { import Koa from ‘koa’; ^^^

SyntaxError: Unexpected identifier at new Script (vm.js:74:7) at compileCode (/usr/local/lib/node_modules/bytenode/index.js:28:16) at Object.compileFile (/usr/local/lib/node_modules/bytenode/index.js:147:22) at /usr/local/lib/node_modules/bytenode/cli.js:47:18 at Array.forEach (<anonymous>) at Object.<anonymous> (/usr/local/lib/node_modules/bytenode/cli.js:38:17) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions…js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12)

How can I solve this problem? thanks.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

Could it be possible, the same way we generate CommonJS modules, to add another flag to create ESM ones?

Another simpler solution is to add an extra step in your setup (which should be fairly easy and straightforward): transpile your ESM code into CommonJS before using Bytenode.

@OsamaAbbas Is there any way to still implement ESM, it appears to be the future of node. It would be very nice