bpmn-io / bpmn-auto-layout

Layout BPMN diagrams, generating missing DI information.
https://bpmn-io.github.io/bpmn-auto-layout/
52 stars 41 forks source link

CommonJS exports should use the `.cjs` extension #39

Closed mortenab closed 1 year ago

mortenab commented 1 year ago

Describe the Bug

It's not possible to import the bpmn-auto-layout module in Node when the importing project is using CommonJS module imports.

Steps to Reproduce

  1. Create a Node project using CommonJS modules ("type": "commonjs" in package.json)
  2. Install the bpmn-auto-layout in the project.
  3. Create and run a script that requires bpmn-auto-layout
  4. The following error is displayed:
require() of ES Module [path]/node_modules/bpmn-auto-layout/dist/index.js from [path]/create_diagram.ts not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/morten/git/Ashby/backend/node_modules/bpmn-auto-layout/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Expected Behavior

The script should run without errors.

I've patched the package locally to use the .cjs file extension for the CommonJS exports and that fixes the issue for me.

I would be happy to submit a PR to fix the issue.

Environment

nikku commented 1 year ago

This is an oversight, indeed. Do you want to contribute a fix?

mortenab commented 1 year ago

@nikku sure, see #40