zkapp-cli icon indicating copy to clipboard operation
zkapp-cli copied to clipboard

Deploy a smart contract within a folder

Open iam-dev opened this issue 1 year ago • 5 comments

Describe the bug

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

  • src -- guardians --- GuardianZkApp.ts

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 avatar Feb 23 '24 09:02 iam-dev

Build folder structure: Scherm­afbeelding 2024-02-23 om 10 48 04

iam-dev avatar Feb 23 '24 09:02 iam-dev

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?

ymekuria avatar Feb 23 '24 09:02 ymekuria

No, this works fine under src folder

iam-dev avatar Feb 23 '24 16:02 iam-dev

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

emlautarom1 avatar Apr 08 '24 15:04 emlautarom1

@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.

Shigoto-dev19 avatar Aug 23 '24 06:08 Shigoto-dev19