Confused ES Modules implications

I have written a Node CLI utility which doesn’t use the browser in any fashion. It reads a BPMN file and generates a couple of text files used for documentation.

When I updated from the older version of the BPMN-Moddle package to the current one, I got some 'exports" errors. I know these are related to the module construction of the BPMN-Moddle package.

Sample of error

\users\jschust2\Dropbox\myDev\CANM2ADOC Development\node_modules\bpmn-moddle\index.js:1
(function (exports, require, module, __filename, __dirname) { export {
^^^^^^
SyntaxError: Unexpected token export

My Node version was a 8.x.x so I updated it to 10.15.x and I’m still getting the same “exports” errors.

If I use Webpack I think I still need to use Babel to compile this into something that will run in Node 10.15.x or the 8.x.x (Some Goverment customers stuck with v8.x.x). Since I’m not using a browser I’m thinking webpack is overkill. I trhink I can use babel directly

My main code is ES6 based and if I transpile backwards using the (env) presets, all that ES6 effort gets undone. I think I need to create a Babel SPECIAL preset that just addresses the module functions used in the latest BPMN-Moddle.

Even after using babel with the ENV presets and testing the Babel generated code I’m getting the same error here.

Maybe I’m headed down the wrong trail completely here and any suggestions are appreciated.

As stated in the projects README:

As of version 5.0.0 this library exposes ES modules. Use esm to consume it or an ES module aware bundler such as Webpack or Rollup to bundle it for the browser.

Yes, I read that. I missed the ESM reference as an alternative to Babel.

When I read the sentence it sounded like use ESM that is in Webpack or the ESM that is in rollup.

I now have something new to do.

Thank you.

1 Like

What if you’re not using in a browser and simply from a nodejs process that is already using es6? You wouldnt want to use webpack at all in that case.

Node does not support ES modules, the essential part this is about.

Other than that, our libraries are browser only, there is little use case running them in Node (as they depend on a lot of DOM / browser APIs.