SyntaxError: Unexpected token '.' while deploying faucet service
While deploying the faucet service for a chain on my VM, I faced the following issue:
/home/skc/faucet/node_modules/@cosmjs/crypto/build/pbkdf2.js:60
let subtle = globalThis?.crypto?.subtle;
^
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/skc/faucet/node_modules/@cosmjs/crypto/build/bip39.js:5:18)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
I have tried node version v16.16.0 and v20.11.0 I tried it with yarn version 1.22.19 and 3.6.3
The optional chaining operator should be available starting from Node.js 14 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#browser_compatibility). Not sure what the issue is.
Can you explain more what you are trying to do? What is "my VM"?
CosmJS 0.34 required node.js 18 CosmJS 0.35 required node.js 20
So optional chaining should be natively available in all supported environments. If you are still experiencing this issue feel free to re-open with more details of the execution environment.