o1-labs / docs2

Docs website for the Mina Protocol.
https://docs.minaprotocol.com
83 stars 129 forks source link

Document how to use zkApps with create-react-app #44

Closed mitschabaude closed 1 year ago

mitschabaude commented 2 years ago

Quoting a great write-up shared by from Gordon Freeman on discord:

  1. npx create-react-app --template typescript

  2. npm run eject

  3. add the following line to the config/webpack.config.json in the return statement experiments: { topLevelAwait: true }, (on my setup it is before the line target: ['browserslist'],)

  4. go to your zkapp project and type: npm link

  5. go to your react app and type: npm link 5.1. make sure that the name matches the name in your zkapp package.json 5.2 if there is a type stuff error during import use this // @ts-ignore right before the import statement in your react app // @ts-ignore import { Multisignature } from 'zkapp-multisign' https://stackoverflow.com/questions/64732623/react-typescript-cannot-find-module-or-its-corresponding-type-declaration

  6. if there is an import error you might have to set the file extension of your zkapp in

    /build/src/index.js manually (like this: import { Multisignature } from './Multisignature.js';) -- .js is the important part 6.1 Don't forget to add this file extension after every build of your zkapp
jasongitmail commented 1 year ago

Closing as an old issue.

We built support for NextJS into the zkApp CLI (via zk project <name> --ui next) and have chosen to focus our efforts and guide devs down NextJS path b/c it's a better, modern framework, a CRA workflow that requires using 'eject' will leave devs with a maintainence headache long term, etc.