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

@semaphore-protocol/proof@v4.0.0-beta.x cannot be used with ES modules #713

Closed
cedoor opened this issue Mar 18, 2024 · 0 comments · Fixed by #716 or #755
Closed

@semaphore-protocol/proof@v4.0.0-beta.x cannot be used with ES modules #713

cedoor opened this issue Mar 18, 2024 · 0 comments · Fixed by #716 or #755
Assignees
Labels
bug 🐛 Something isn't working

Comments

@cedoor
Copy link
Member

cedoor commented Mar 18, 2024

Describe the bug

@semaphore-protocol/proof doesn't work with ES modules, because, in turn, 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).

To Reproduce

import { generateProof } from "@semaphore-protocol/proof"

console.log(generateProof)
{
    "type": "module",
    "dependencies": {
        "@semaphore-protocol/proof": "^4.0.0-beta.2"
    }
}

Error

(node:32193) 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

Expected behavior

@semaphore-protocol/proof should work when imported into an ES module.

Additional context

Related issues:

@cedoor cedoor added this to the Semaphore V4 milestone Mar 18, 2024
@cedoor cedoor added the bug 🐛 Something isn't working label Mar 18, 2024
cedoor added a commit that referenced this issue Mar 19, 2024
Adding the 'resolutions' field with the static version of web-worker solves the problem described in
issue #713. To be regarded as a temporary solution.

re #713
cedoor added a commit that referenced this issue Mar 19, 2024
overrides only works with NPM and both overrides and resolutions works if they are in the project
root package.json. So they don't solve #713.

re #713
@cedoor cedoor reopened this Mar 19, 2024
cedoor added a commit that referenced this issue Mar 28, 2024
Adding the 'resolutions' field with the static version of web-worker solves the problem described in
issue #713. To be regarded as a temporary solution.

re #713


Former-commit-id: ca36ed5
cedoor added a commit that referenced this issue Mar 28, 2024
overrides only works with NPM and both overrides and resolutions works if they are in the project
root package.json. So they don't solve #713.

re #713


Former-commit-id: b77feeb
@cedoor cedoor self-assigned this Apr 26, 2024
cedoor added a commit that referenced this issue Apr 26, 2024
cedoor added a commit that referenced this issue Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
Status: ✔️ Done
1 participant