BitGo/BitGoJS

Issue with ESM mode

Opened this issue · 0 comments

Environment Details

  • OS: AWS AMI Linux
  • Node Version: v14.17.4 / v14.19.3 / v16.15.0
  • Yarn Version: NPM 6.14.14 / 6.14.17 / 8.5.5
  • BitGoJS Version: 13.0.1 / 13.1.0 / 16.2.1
  • BitGo Environment: testnet

Expected Behavior

Current Behavior

Trying to run the application with ESM in all the abovementioned environments.

pm2 start index.js --node-args="-r esm" --name="bank" -f

Getting the following error:

/home/ec2-user/.nvm/versions/node/v14.17.4/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:1
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /srv/web/cc-bank/node_modules/@polkadot/keyring/pair/decode.js
require() of ES modules is not supported.
require() of /srv/web/cc-bank/node_modules/@polkadot/keyring/pair/decode.js from /srv/web/cc-bank/node_modules/@bitgo/sdk-coin-dot/dist/src/lib/utils.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 decode.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /srv/web/cc-bank/node_modules/@polkadot/keyring/package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1089:13)
at Object.Hook._require.Module.require (/home/ec2-user/.nvm/versions/node/v14.17.4/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39) {
code: 'ERR_REQUIRE_ESM'
}