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.
PoC
https://github.com/LavaMoat/docs/blob/main/react-native-and-ses-lockdown.md
Discussion
One sample error obtained
Where is this
readonly property?node_modules/ethjs/lib/index.jswhich calls
node_modules/ethjs/node_modules/ethjs-query/lib/index.jsThis is the first line of the file within the bundle. Let's call the
_$$REQUIRE()function from the consoleThrows
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
ethlibrariesTo the following files...
node_modules/ethjs/node_modules/ethjs-query/package.jsonnode_modules/ethjs-contract/package.jsonnode_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
--excludeis needed to be able to include thepackage.jsonfile into the patch.Items of Action