Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snarkjs cannot be used with ES modules #476

Closed
cedoor opened this issue Mar 18, 2024 · 0 comments · Fixed by #484 or semaphore-protocol/semaphore#755
Closed

snarkjs cannot be used with ES modules #476

cedoor opened this issue Mar 18, 2024 · 0 comments · Fixed by #484 or semaphore-protocol/semaphore#755

Comments

@cedoor
Copy link

cedoor commented Mar 18, 2024

Description

snarkjs cannot be used with ES modules as some iden3 packages depend on web-worker@1.3.0, which for some reason doesn't include type: "module" in its package.json (and exports its ES modules with .js instead of .mjs). Related issue: developit/web-worker#44.

Here are the dependencies that cause this problem:

  • r1csfile@0.0.47 -> ffjavascript@0.2.60 -> web-worker@^1.2.0
  • circom_runtime@0.1.24 -> ffjavascript@0.2.60 -> web-worker@^1.2.0

web-worker@1.2.0 works fine but ^ makes package managers (Yarn for sure) to download the latest minor, i.e. v1.3.0.

ffjavascript@0.2.63 seems to fix it by using a fixed version (precisely v1.2.0) and r1csfile and circom_runtime on Github seem to depend on ffjavascript@0.2.63, but their latest version was actually released with ffjavascript@0.2.60, as you can check on NPM:

I guess 1 solution here is just to release a new version of r1csfile and circom_runtime first, and then a new version of snarkjs with those dependencies updated.

Example

index.js:

import { groth16 } from "snarkjs"

console.log(groth16)

package.json:

{
    "type": "module",
    "dependencies": {
        "snarkjs": "^0.7.3"
    }
}

Error

(node:30967) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/cedoor/Downloads/tests/snarkjs/node_modules/circom_runtime/node_modules/web-worker/node.js:17
import URL from 'url';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:345:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:294:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)

Node.js v20.10.0

Other information:

Using Yarn v4.1.0 and NodeJS v20.10.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant