Issue
Hi everyone, I have a project that is using a dependency that is dependent on the keccak file from ethereum-cryptography@1.0.3 library. I then bundle my project into a single JS file using the ncc build command.
Now the issue is that ncc transforms this code to the code below as ncc can't find the crypto package for some reason:
This leads to my project crashing with this error when I try run it:
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'
}
I've confirmed that this issue is also happening when I try to build the ethereum-cryptography package by itself.
Steps to repro
Run from the root of the ethereum-cryptography repository.
Add @vercel/ncc package yarn add @vercel/ncc
Build the keccak.ts file. ncc build keccak.js -o bundle/index.js
This should have created a new directory named bundle in the root folder with an index.js file. Inspect the generated index.js file and find the code below
exports.crypto = (() => {
const webCrypto = typeof self === "object" && "crypto" in self ? self.crypto : undefined;
const nodeRequire = true &&
__nccwpck_require__(387).bind(module); ------>. The node ID might be different
return {
node: nodeRequire && !webCrypto ? nodeRequire("crypto") : undefined,
web: webCrypto
};
})();
The module with ID 387 resolves to the code below
/***/ 387:
/***/ ((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 = 387;
module.exports = webpackEmptyContext;
**Expected Behavior**
Running `ncc build` does not generate a `webpackEmptyContext` function when looking for the `crypto` module.
**Versions**
`@vercel/ncc`: 0.34.0
Any suggestions on what to check are appreciated! Thanks in advance.
Issue Hi everyone, I have a project that is using a dependency that is dependent on the
keccak
file fromethereum-cryptography@1.0.3
library. I then bundle my project into a single JS file using thencc build
command.Now the issue is that
ncc
transforms this code to the code below asncc
can't find thecrypto
package for some reason:This leads to my project crashing with this error when I try run it:
I've confirmed that this issue is also happening when I try to build the
ethereum-cryptography
package by itself.Steps to repro
Run from the root of the
ethereum-cryptography
repository.@vercel/ncc
packageyarn add @vercel/ncc
keccak.ts
file.ncc build keccak.js -o bundle/index.js
bundle
in the root folder with anindex.js
file. Inspect the generatedindex.js
file and find the code belowfunction webpackEmptyContext(req) { var e = new Error("Cannot find module '" + req + "'"); e.code = 'MODULE_NOT_FOUND'; throw e; } webpackEmptyContext.keys = () => ([]); webpackEmptyContext.resolve = webpackEmptyContext; webpackEmptyContext.id = 387; module.exports = webpackEmptyContext;