Skip to content

Proof of Concept Insights - Attempt to assign a readonly property - Web3 libs using babel regenerator #7

@bentobox19

Description

@bentobox19

PoC

https://github.com/LavaMoat/docs/blob/main/react-native-and-ses-lockdown.md

Discussion

One sample error obtained

TypeError: Attempted to assign to readonly property.

ERROR  Error: Requiring module "node_modules/ethjs/node_modules/ethjs-query/lib/index.js", which threw an exception: TypeError: Attempted to assign to readonly property.
ERROR  TypeError: undefined is not a constructor (evaluating 'new (_$$_REQUIRE(_dependencyMap[0], "ethjs-query"))(cprovider, self.options.query)'

Where is this readonly property ?

  • node_modules/ethjs/lib/index.js
var query = new (_$$_REQUIRE(_dependencyMap[0], "ethjs-query"))(cprovider, self.options.query);

which calls

  • node_modules/ethjs/node_modules/ethjs-query/lib/index.js
var _regenerator2 = _interopRequireDefault(_$$_REQUIRE(_dependencyMap[0], "babel-runtime/regenerator"));

This is the first line of the file within the bundle. Let's call the _$$REQUIRE() function from the console

_$$_REQUIRE(_dependencyMap[0], "babel-runtime/regenerator")

Throws

Error: Requiring module "node_modules/babel-runtime/regenerator/index.js", which threw an exception: TypeError: Attempted to assign to readonly property.

We have already removed the regenerator plugin. Investigating into the library, we found that it's referenced in its package.json. Further grepping show us more libraries with the same problem.

Proposed Solution

Patch some eth libraries

To the following files...

  • node_modules/ethjs/node_modules/ethjs-query/package.json
  • node_modules/ethjs-contract/package.json
  • node_modules/ethjs/node_modules/ethjs-contract/package.json

...Do the following change:

"main": "lib/index.js", - > "main": "src/index.js",

And invoke npx patch-package --exclude "nothing" <LIB_NAME>.
This flag --exclude is needed to be able to include the package.json file into the patch.

Items of Action

  • Either keep this way of dealing with packages leveraging babel regenator, or
  • Send PRs to these repositories.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions