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

CLI beta38 errors with "Unexpected token 'export'" when installed via npm #1597

Closed
spalladino opened this issue Aug 16, 2023 · 1 comment · Fixed by #1628
Closed

CLI beta38 errors with "Unexpected token 'export'" when installed via npm #1597

spalladino opened this issue Aug 16, 2023 · 1 comment · Fixed by #1628
Assignees
Labels
T-bug Type: Bug. Something is broken.

Comments

@spalladino
Copy link
Collaborator

When installing the CLI with npm, any command fails with:

➜  ~ aztec-cli --version      
/home/josh/.nvm/versions/node/v18.17.1/lib/node_modules/@aztec/cli/node_modules/@noir-lang/noir-source-resolver/lib/index.js:2
export let read_file = function (source_id) {
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at Object.<anonymous> (/home/josh/.nvm/versions/node/v18.17.1/lib/node_modules/@aztec/cli/node_modules/@noir-lang/noir-source-resolver/lib/index_node.js:4:20)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)

(thanks @critesjosh for the report)

@spalladino spalladino added the T-bug Type: Bug. Something is broken. label Aug 16, 2023
@spalladino spalladino self-assigned this Aug 16, 2023
@spalladino spalladino added this to A3 Aug 16, 2023
@github-project-automation github-project-automation bot moved this to Todo in A3 Aug 16, 2023
@spalladino
Copy link
Collaborator Author

This is caused by noir-source-resolver package.json, which is intended to be released as both cjs and esm. Apparently version 1.1.1 of the package works fine, but noir_wasm declares 1.1.2 as peer dependency, which fails.

This is also the reason why it works with yarn and not with npm: yarn does not install peer dependencies by default, so the version of source-resolver that gets installed is 1.1.1 as required by our noir-compiler. On the other hand, npm install 1.1.1 locally for the noir-compiler package, but also installs 1.1.2 in the project root to be used by noir_wasm.

This means the issue can be sidestepped by manually installing 1.1.1 of the resolver along with the CLI, like:

npm i @noir-lang/noir-source-resolver@1.1.1

It seems that noir-resolver recently got a fix by @ludamad which may solve this issue. We're waiting on a release of that package to update and see if it fixes things.

@spalladino spalladino moved this from Todo to Blocked in A3 Aug 16, 2023
spalladino added a commit that referenced this issue Aug 18, 2023
Issue #1597 was
preventing users from installing the Aztec CLI via npm.

Releasing a new version of `noir_wasm` and `noir-source-resolver` didn't
fix the issue unfortunately, and further tweaking `noir-source-resolver`
so it's loaded properly leads to errors due since [the resolver is a
global
object](https://nodejs.org/api/packages.html#approach-2-isolate-state)
but it's treated as different objects when loaded as commonjs or esm. So
the noir-compiler here is properly configuring the resolver in esm-land,
but noir_wasm loads it via commonjs and fails. To make things worse,
jest seems to be complaining about misconfigured esm modules here.

Given that noir_wasm is not kept up-to-date atm and is not the
recommended way to compile noir contracts, I decided to time out and
remove it altogether for now. I'm creating a new issue to revisit this
in the future.

Fixes #1597
@github-project-automation github-project-automation bot moved this from Blocked to Done in A3 Aug 18, 2023
AztecBot pushed a commit to AztecProtocol/docs that referenced this issue Aug 18, 2023
Issue AztecProtocol/aztec-packages#1597 was
preventing users from installing the Aztec CLI via npm.

Releasing a new version of `noir_wasm` and `noir-source-resolver` didn't
fix the issue unfortunately, and further tweaking `noir-source-resolver`
so it's loaded properly leads to errors due since [the resolver is a
global
object](https://nodejs.org/api/packages.html#approach-2-isolate-state)
but it's treated as different objects when loaded as commonjs or esm. So
the noir-compiler here is properly configuring the resolver in esm-land,
but noir_wasm loads it via commonjs and fails. To make things worse,
jest seems to be complaining about misconfigured esm modules here.

Given that noir_wasm is not kept up-to-date atm and is not the
recommended way to compile noir contracts, I decided to time out and
remove it altogether for now. I'm creating a new issue to revisit this
in the future.

Fixes AztecProtocol/aztec-packages#1597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: Bug. Something is broken.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant