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

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

Closed
bentobox19 opened this issue Feb 26, 2022 · 1 comment

Comments

@bentobox19
Copy link
Contributor

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.
@bentobox19 bentobox19 changed the title Proof of Concept Insights - Attempt to assign a readnly property - Web3 Libraries using babel regenerator Proof of Concept Insights - Attempt to assign a readonly property - Web3 libs using babel regenerator Feb 26, 2022
@leotm leotm added metamask-mobile jsc JavaScriptCore lockdown and removed jsc JavaScriptCore labels Mar 12, 2023
@leotm leotm added this to the MM + Lockdown milestone Mar 20, 2023
@leotm
Copy link
Member

leotm commented Aug 17, 2023

@leotm leotm closed this as completed Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants