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
Create a Node project using CommonJS modules ("type": "commonjs" in package.json)
Install the bpmn-auto-layout in the project.
Create and run a script that requires bpmn-auto-layout
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.
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
"type": "commonjs"
inpackage.json
)bpmn-auto-layout
in the project.bpmn-auto-layout
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