How can I import cytoscape.js into my npm ESM project?
Versions I use are: npm: '8.1.4', node: '14.15.3'.
My package.json defines that I want to do ESM:
"type": "module",
The cytoscape.js documentation states the following:
To install Cytoscape.js via npm:
npm install cytoscapeTo use Cytoscape.js in an ESM environment with npm (e.g. Webpack or Node.js with the esm package):
import cytoscape from 'cytoscape';
I followed the instructions. However, the import results in the error:
Uncaught SyntaxError: The requested module './../../node_modules/cytoscape/dist/cytoscape.cjs.js' does not provide an export named 'default'
Well, that is correct since the commonjs version was loaded. But in an ESM environment cytoscape.esm.js should be loaded instead of cytoscape.cjs.js. However, node_modules/cytoscape/package.json says to use the commonjs version: "main": "dist/cytoscape.cjs.js",
So I tried to import the ESM version directly in my code:
import cytoscape from './../../node_modules/cytoscape/dist/cytoscape.esm.js';
Cytoscape.js is now imported. However, I get the followup error in an dependent package:
Uncaught SyntaxError: The requested module './../../heap/index.js' does not provide an export named 'default' in line cytoscape.esm.js:24
I'm kind of stuck now. Other related questions did not help so far. I'll be happy for any suggestion or even solution. Thanks in advance!