-
Notifications
You must be signed in to change notification settings - Fork 311
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
Patch ethereum-cryptography-1.1.2 to work with ncc #2211
Conversation
|
db6d50a
to
c310c7c
Compare
const webCrypto = typeof self === "object" && "crypto" in self ? self.crypto : undefined; | ||
const nodeRequire = typeof module !== "undefined" && | ||
- typeof module.require === "function" && | ||
- module.require.bind(module); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HenryNguyen5 we could use your help with this issue. cc @cds95
Any idea on the purpose of binding the require fn, module.require.bind(module)
?
ncc
builds are failing withError: Cannot find module 'crypto'
at this line.- This PR is the temporary fix to avoid this issue.
ncc
transforms the code to this:
exports.crypto = (() => {
const webCrypto = typeof self === "object" && "crypto" in self ? self.crypto : undefined;
const nodeRequire = true &&
__nccwpck_require__(84310).bind(module); <-- Note the
return {
node: nodeRequire && !webCrypto ? require("crypto") : undefined,
web: webCrypto
};
})();
/***/ 84310:
/***/ ((module) => {
function webpackEmptyContext(req) {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
}
webpackEmptyContext.keys = () => ([]);
webpackEmptyContext.resolve = webpackEmptyContext;
webpackEmptyContext.id = 84310;
module.exports = webpackEmptyContext;
/***/ }),
This leads to the EA crash looping with this error:
Error: Cannot find module 'crypto'
at Object.webpackEmptyContext (/Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:183577:10)
at /Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:83270:43
at Object.78777 (/Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:83273:3)
at __nccwpck_require__ (/Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:183842:43)
at Object.35681 (/Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:83194:17)
at __nccwpck_require__ (/Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:183842:43)
at Object.30038 (/Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:169615:16)
at __nccwpck_require__ (/Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:183842:43)
at Object.55944 (/Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:168123:14)
at __nccwpck_require__ (/Users/christophersastropranoto/Documents/external-adapters-js/packages/sources/layer2-sequencer-health/bundle/index.js:183842:43) {
code: 'MODULE_NOT_FOUND'
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think webpack is trying to bundle crypto
when it's a native module. You could try the following ncc
flag: --external crypto
.
If that doesn't work, I would try upgrading ncc
to latest to see if it fixes the require statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried both of those already and still no luck :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I even tried building the js-ethereum-cryptography
project directly and still see the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure how important it is to not patch a package. But you could also abandon ncc and switch it up for something like swc or esbuild + do a prod only install for deps.
package.json
Outdated
"resolutions": { | ||
"[email protected]": "patch:ethereum-cryptography@npm%3A1.1.2#./.yarn/patches/ethereum-cryptography-npm-1.1.2-c16cfd7e8a.patch", | ||
"ethereum-cryptography@^1.0.3": "patch:ethereum-cryptography@npm%3A1.1.2#./.yarn/patches/ethereum-cryptography-npm-1.1.2-c16cfd7e8a.patch", | ||
"ethereum-cryptography@^0.1.3": "patch:ethereum-cryptography@npm%3A1.1.2#./.yarn/patches/ethereum-cryptography-npm-1.1.2-c16cfd7e8a.patch" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cds95 we should investigate if we can remove 0.1.3
version altogether and move to v1
d445d6f
to
0c23bd5
Compare
@krebernisak @HenryNguyen5 I've opened an issue in the Edit: I've been told to open another issue at NCC, which I have done here vercel/ncc#985 |
Was a fix for this already merged in? Should we close this PR? |
Please re-open if this is still relevent |
No description provided.