force-graph icon indicating copy to clipboard operation
force-graph copied to clipboard

bezier-js dep not commonjs compatible?

Open kumavis opened this issue 5 years ago • 9 comments
trafficstars

package versions

force-graph: "1.35.0"
bezier-js "3.0.2"

steps to reproduce

node ../../node_modules/force-graph/dist/force-graph.common.js
internal/modules/cjs/loader.js:1031
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/xyz/Development/lavamoat/node_modules/bezier-js/dist/bezier.js
require() of ES modules is not supported.
require() of /home/xyz/Development/lavamoat/node_modules/bezier-js/dist/bezier.js from /home/xyz/Development/lavamoat/node_modules/force-graph/dist/force-graph.common.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename bezier.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/xyz/Development/lavamoat/node_modules/bezier-js/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1031:13)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/xyz/Development/lavamoat/node_modules/force-graph/dist/force-graph.common.js:13:16)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14) {
  code: 'ERR_REQUIRE_ESM'
}
lavamoat/packages/tofu on  perf-moar [$✘!+?] is 📦 v5.1.1 via ⬢ v12.19.0 
⇡0% ➜ npx browserify ../../node_modules/force-graph/dist/force-graph.common.js 

/home/xyz/Development/lavamoat/node_modules/bezier-js/dist/bezier.js:2236
export { Bezier };
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

introduced here https://github.com/vasturiano/force-graph/commit/3d9703c466c8f555c8bc5a6a710f2a9fd6ef6718

kumavis avatar Nov 02 '20 07:11 kumavis

[email protected] works

kumavis avatar Nov 02 '20 07:11 kumavis

@kumavis this is related to the recent version of bezier-js. If you are having issues importing that library, please mention a new issue in that repo.

vasturiano avatar Nov 03 '20 06:11 vasturiano

I opened an issue with bezier-js but also here because your commonjs distributable force-graph/dist/force-graph.common.js is now not commonjs compatible

kumavis avatar Nov 04 '20 05:11 kumavis

@kumavis ok thanks for that. I've published a new version of this module that includes bezier-js latest patch, so it should be fixed. Let me know if you experience any further issues.

vasturiano avatar Nov 04 '20 08:11 vasturiano

same issue with [email protected]

kumavis avatar Nov 06 '20 02:11 kumavis

@vasturiano PR'd a potential solution for bezierjs https://github.com/Pomax/bezierjs/pull/138

kumavis avatar Nov 06 '20 02:11 kumavis

Same problem here. I tried the versions 1.35.1, 1.35.2, 1.36.2 and 1.39.2.

LukasPol avatar Mar 30 '21 19:03 LukasPol

Any workarounds for this?

paulkre avatar May 31 '22 18:05 paulkre

Any workaround for this?

aertoria avatar Jan 31 '23 08:01 aertoria