MetaMask / snaps

Extend the functionality of MetaMask using Snaps
https://metamask.io/snaps/
Other
720 stars 553 forks source link

Build error: Can't walk dependency graph: Cannot find module #365

Closed danfinlay closed 2 years ago

danfinlay commented 2 years ago

I started making a snap for EIP-712 signTypedData_v5, to somewhat test the theory that flask could be a place for prototyping new signature methods as I claimed on twitter.

I hit an issue with dependency resolution. This may be a problem with the fact that I tried to specify this particular dependency from a specific commit of a user's github repository. Maybe the current build process doesn't play friendly with these? I'm not sure why else, the module appears to be in my node_modules directory.

I installed the modified version of eth-sig-util using this command:

I hoped this would hash-lock the snap dependency at cammellos's latest commit for this (which he namespaces as v4, but I expose as v5) available here.

Curious if anyone else has experienced this or has a lead on the solution.

The error I got:

➜  signTypedData_v5_snap git:(main) mm-snap build
Build error: Can't walk dependency graph: Cannot find module './eth-sig-util' from '/Users/danfinlay/Documents/signTypedData_v5_snap/src/index.js'
    required by /Users/danfinlay/Documents/signTypedData_v5_snap/src/index.js
Error: Can't walk dependency graph: Cannot find module './eth-sig-util' from '/Users/danfinlay/Documents/signTypedData_v5_snap/src/index.js'
    required by /Users/danfinlay/Documents/signTypedData_v5_snap/src/index.js
    at /Users/danfinlay/.nvm/versions/node/v14.18.0/lib/node_modules/@metamask/snaps-cli/node_modules/resolve/lib/async.js:167:35
    at load (/Users/danfinlay/.nvm/versions/node/v14.18.0/lib/node_modules/@metamask/snaps-cli/node_modules/resolve/lib/async.js:186:43)
    at onex (/Users/danfinlay/.nvm/versions/node/v14.18.0/lib/node_modules/@metamask/snaps-cli/node_modules/resolve/lib/async.js:211:17)
    at /Users/danfinlay/.nvm/versions/node/v14.18.0/lib/node_modules/@metamask/snaps-cli/node_modules/resolve/lib/async.js:24:69
    at FSReqCallback.oncomplete (fs.js:191:21) {
  code: 'MODULE_NOT_FOUND',
danfinlay commented 2 years ago

I've confirmed that if I install @metamask/eth-sig-util I have no problems. It seems like some mismatch between how I'm specifying the version of the module to install, maybe how yarn is referencing it, and then how browserify is walking that trie.

rekmarks commented 2 years ago

I don't know why this would happen, but since there is a reasonably simple workaround and related to Browserify, I will mark this as wontfix. I am reasonably confident it's related to Browserify because their resolve package is in your stack trace: https://npmjs.com/package/resolve

Now, to expand on our philosophy here, mm-snap build is supposed to be a useful default that handles the majority of use cases. It uses Browserify under the hood because we use Browserify at MetaMask, and we have found that other popular bundlers (e.g. Rollup and Webpack) are similarly if not more finicky in practice. As of version 0.12.0 of this monorepo, we have started shipping bundler plugins that contain our transforms to make it easy for people to bring their own bundlers.

In conclusion, if there were no workaround for this we might take a closer look, but since there is a workaround, I will close the issue outright.