Confused ES Modules implications


#1

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.


#2

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.


#3

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.