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

Patch ethereum-cryptography-1.1.2 to work with ncc #2211

Open
wants to merge 2 commits into
base: develop-starknet
Choose a base branch
from

Conversation

krebernisak
Copy link
Contributor

No description provided.

@krebernisak krebernisak requested a review from cds95 October 3, 2022 13:07
@changeset-bot
Copy link

changeset-bot bot commented Oct 3, 2022

⚠️ No Changeset found

Latest commit: 0c23bd5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

const webCrypto = typeof self === "object" && "crypto" in self ? self.crypto : undefined;
const nodeRequire = typeof module !== "undefined" &&
- typeof module.require === "function" &&
- module.require.bind(module);
Copy link
Contributor Author

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 with Error: 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'
}

Copy link
Collaborator

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.

Copy link
Collaborator

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 :(

Copy link
Collaborator

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.

Copy link
Collaborator

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": {
"ethereum-cryptography@1.1.2": "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"
Copy link
Contributor Author

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

@cds95 cds95 temporarily deployed to QA October 3, 2022 15:21 Inactive
@krebernisak krebernisak force-pushed the fix/ethereum-cryptography-1.1.2-ncc branch from d445d6f to 0c23bd5 Compare October 3, 2022 15:26
@krebernisak krebernisak temporarily deployed to QA October 3, 2022 15:27 Inactive
@cds95
Copy link
Collaborator

cds95 commented Oct 4, 2022

@krebernisak @HenryNguyen5 I've opened an issue in the js-ethereum-cryptography repo here.

Edit: I've been told to open another issue at NCC, which I have done here vercel/ncc#985

@boxhock
Copy link
Contributor

boxhock commented Oct 28, 2022

Was a fix for this already merged in? Should we close this PR?

@HenryNguyen5 HenryNguyen5 removed their request for review November 17, 2022 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants