|
| 1 | +# With Expo TypeScript |
| 2 | + |
| 3 | +[](https://itunes.apple.com/app/apple-store/id982107779) |
| 4 | +[](https://play.google.com/store/apps/details?id=host.exp.exponent&referrer=www) |
| 5 | +[](https://docs.expo.io/workflow/web/) |
| 6 | + |
| 7 | +This is a starter project for creating universal React apps with Next.js, Expo, and TypeScript. |
| 8 | + |
| 9 | +> 💡 For the most updated info, see the [Expo + Next.js Docs](https://docs.expo.io/guides/using-nextjs/)! |
| 10 | +
|
| 11 | + |
| 12 | + |
| 13 | +- Next.js cannot be used for SSR in your native app. |
| 14 | +- The native bundle is built using the [Metro bundler](https://facebook.github.io/metro/) and may not have the same level of optimization as the web bundle which is compiled using the Next.js Webpack configuration. |
| 15 | +- Expo transpiles `react-native-web` packages by default to enable the use of `react-native` in a browser or Node.js environment. |
| 16 | +- All [Expo packages](https://docs.expo.io/versions/latest/) work in the browser. If you experience issues using them in a Node environment, please report them here: [Expo issues](https://github.com/expo/expo/issues). |
| 17 | +- Most community `react-native-*` packages do not support web, please refer to [reactnative.directory](https://reactnative.directory/?web=true) for a list of web compatible packages. |
| 18 | +- Eject the `pages/_document` component by running `yarn next-expo customize`. |
| 19 | +- To use fonts and images, see [the Expo docs](https://docs.expo.io/guides/using-nextjs/#image-support). |
| 20 | + |
| 21 | +## Deploy your own |
| 22 | + |
| 23 | +Deploy the example using [Vercel](https://vercel.com) (web only): |
| 24 | + |
| 25 | +[](https://vercel.com/import/project?template=https://github.com/zeit/next.js/tree/canary/examples/with-expo) |
| 26 | + |
| 27 | +Deploy the native app to the App store and Play store using [Expo deployment](https://docs.expo.io/distribution/app-stores/). |
| 28 | + |
| 29 | +## How to use |
| 30 | + |
| 31 | +### Using `create-next-app` |
| 32 | + |
| 33 | +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: |
| 34 | + |
| 35 | +```bash |
| 36 | +npx create-next-app --example with-expo with-expo-app |
| 37 | +# or |
| 38 | +yarn create next-app --example with-expo with-expo-app |
| 39 | +``` |
| 40 | + |
| 41 | +### Running web |
| 42 | + |
| 43 | +> 🚨 Using default Expo web with Next.js is not supported. |
| 44 | +
|
| 45 | +- Start the Next.js project with `yarn dev` (`yarn next dev`). |
| 46 | + |
| 47 | +Deploy the web app to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). |
| 48 | + |
| 49 | +### Running native |
| 50 | + |
| 51 | +- Install the Expo CLI `npm i -g expo-cli`. |
| 52 | +- Start the Metro bundler with `yarn ios` or `yarn android` -- This runs `expo start` with the Expo CLI. |
| 53 | +- You can run the mobile app using the [Expo client app](https://expo.io/tools), or by running `yarn eject` and building the project manually (this requires a macbook for iOS). |
| 54 | + |
| 55 | +Deploy the native app to the App store and Play store using [Expo deployment](https://docs.expo.io/distribution/app-stores/). |
| 56 | + |
| 57 | +## Troubleshooting |
| 58 | + |
| 59 | +You may find that certain packages like `@ui-kitten/components` do not work in the browser. This is because they need to be transpiled by Next.js, you can fix this by doing the following: |
| 60 | + |
| 61 | +- Install the following: |
| 62 | + |
| 63 | +```sh |
| 64 | +yarn add -D next-compose-plugins next-transpile-modules |
| 65 | +``` |
| 66 | + |
| 67 | +- Modify the Next.js config `next.config.js`: |
| 68 | + |
| 69 | +```js |
| 70 | +const { withExpo } = require('@expo/next-adapter') |
| 71 | +const withPlugins = require('next-compose-plugins') |
| 72 | +const withTM = require('next-transpile-modules')([ |
| 73 | + // Add the name of your package here... |
| 74 | + '@ui-kitten/components', |
| 75 | +]) |
| 76 | + |
| 77 | +module.exports = withPlugins([withTM, [withExpo, { projectRoot: __dirname }]], { |
| 78 | + // ... |
| 79 | +}) |
| 80 | +``` |
0 commit comments