node-cbor: cbor fails to import in expo/metro bundle (expo go IOS)

I’m developing a React Native application and I cannot get this library to work under expo/metro. Simply adding import cbor from 'cbor'; causes the bundle to error out with Unhandled JS Exception: Invalid regular expression: invalid group specifier name no stack.

To reproduce:

expo init dummy  # minimal template
cd dummy
npm install cbor
npm install node-inspect-extracted
npm install stream
# Add "import cbor from 'cbor';" to App.js
expo start
# open bundle with expo go

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 23 (14 by maintainers)

Most upvoted comments

Understanding their code let me simplify a few things. Current set of packages required:

  • bignumber.js (or set dynamicDepsInPackages to “reject”)
  • buffer
  • cbor
  • events
  • node-inspect-extracted
  • stream-browserify

No changes to babel.config.js necessary. Change metro.config.js to:

module.exports = {
  transformer: {
    assetPlugins: ['expo-asset/tools/hashAssetFiles'],
  },
  resolver: {
    extraNodeModules: {
      stream: require.resolve('stream-browserify'),
    },
  },
};