o1-labs / zkapp-cli

CLI to create a zkApp (zero-knowledge app) for Mina Protocol
https://docs.minaprotocol.com/zkapps/how-to-write-a-zkapp
Apache License 2.0
114 stars 43 forks source link

Deploy a smart contract within a folder #593

Open iam-dev opened 6 months ago

iam-dev commented 6 months ago

Describe the bug

I'm trying to deploy a smart contract within a folder. Folder structure:

Command:


zk deploy               
✔ Which deploy alias do you want to deploy to? · berkeley
✔ Build project
✔ Generate build.json
✔ Choose smart contract to deploy · GuardianZkApp
  Your config.json was updated to always use this
  smart contract when deploying to this deploy alias.

Error:

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '../build/src/GuardianZkApp.js' imported from /../.nvm/versions/node/v20.11.0/lib/node_modules/zkapp-cli/src/lib/deploy.js
    at finalizeResolution (node:internal/modules/esm/resolve:264:11)
    at moduleResolve (node:internal/modules/esm/resolve:917:10)
    at defaultResolve (node:internal/modules/esm/resolve:1130:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:328:34)
    at importModuleDynamically (node:internal/modules/esm/translators:158:35)
    at importModuleDynamicallyCallback (node:internal/modules/esm/utils:207:14)
    at deploy (file:///Users/iamdev/.nvm/versions/node/v20.11.0/lib/node_modules/zkapp-cli/src/lib/deploy.js:247:32)
    at async Object.handler (file:///../.nvm/versions/node/v20.11.0/lib/node_modules/zkapp-cli/src/bin/index.js:127:21) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///../build/src/GuardianZkApp.js'
}

Steps to Reproduce

1) Create a smart contract within a new folder. 2) zk deploy 3) choose the new smart contract 4) Error occurred

System Info

Be sure to include the following system information when submitting a GitHub issue:

  System:
    OS: macOS 14.3.1
    CPU: (8) arm64 Apple M2
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
  npmPackages:
    o1js: 0.16.2
  npmGlobalPackages:
    zkapp-cli: 0.17.2

Severity

serious, but I can work around it

Additional Information

No response

iam-dev commented 6 months ago

Build folder structure:

Scherm­afbeelding 2024-02-23 om 10 48 04
ymekuria commented 6 months ago

Thanks for bringing this up @iam-dev. We will take a look at this. Are you experiencing the same problem if all your contracts are directly in the src folder and not nested? Did you enter zk config before entering zk deploy?

iam-dev commented 6 months ago

No, this works fine under src folder

emlautarom1 commented 5 months ago

I can confirm this issue is still present on version 0.18.0. I also had to move the contract to the top level src folder to solve this issue.

The source of the issue seems to be the usage of basename which should probably be resolve in order to use absolute paths:

https://github.com/o1-labs/zkapp-cli/blob/1f2e2ddc8141ab1435931f519ee97bcf80749366/src/lib/deploy.js#L782

Shigoto-dev19 commented 2 weeks ago

@iam-dev Could you confirm if this issue is still occurring? I tried to reproduce it but couldn't encounter the problem. As long as I include the zkApp name in config.json, it deploys successfully, even when located in a nested folder.