Skip to content

Commit

Permalink
chore(docs): Update troubleshooting guide to show SSR error (#5709)
Browse files Browse the repository at this point in the history
  • Loading branch information
esauerbo authored Aug 30, 2024
1 parent 2e3d373 commit dcb3251
Showing 1 changed file with 42 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ This is a known problem when using the `jsdom` library (a dependency of Jest) wi

### Next 13.4+: React Server Components

Next.js 13.4+ introduces [app directory](https://nextjs.org/docs/app/building-your-application/routing#the-app-directory) with the usage of [Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components). To use Amplify UI componenents, you must use them inside the Client Component tree by placing `"use client"` at the boundary between your Client and Server component module graph. Please see the Next.js [documentation](https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-third-party-packages-and-providers) on how you could achieve this.
Next.js 13.4+ introduces [app directory](https://nextjs.org/docs/app/building-your-application/routing#the-app-directory) with the usage of [Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components). Amplify UI components are intended to be used on the client side. See [here](#attempted-import-error-useform-is-not-exported-from-react-hook-form-imported-as-useform) for solutions.

### Next 13.4+: `Module not found` Errors

Expand All @@ -186,6 +186,47 @@ Module not found: Can't resolve 'aws-crt' in 'xxx'

These errors will not affect the use and functionality of the client, nor will errors appear in the browser console. This is a known transitive issue when using the AWS SDK. The issue is currently tracked [here](https://github.com/aws-amplify/amplify-js/issues/11030).

## Server-Side Rendering (SSR)

### Attempted import error: 'useForm' is not exported from 'react-hook-form' (imported as 'useForm').

If you attempt to use Amplify with server-side rendering, you may encounter the following error:

```
./node_modules/@aws-amplify/ui-react-core/dist/esm/components/FormCore/FormProvider.mjs
Attempted import error: 'useForm' is not exported from 'react-hook-form' (imported as 'useForm').
```

Amplify UI components are interactive and designed to work on the client side. To use them inside of Server Components you must wrap them in a Client Component with "use client". For more information, see the Next.js [documentation](https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-third-party-packages-and-providers) on how you could achieve this.

## Vite

### `Uncaught ReferenceError: global is not defined`

<Message
variation="filled"
colorTheme="info"
>
Note: this issue was fixed in `aws-amplify` version 6
</Message>

When working with a [Vite](https://vitejs.dev) project you must make a few modifications. Please follow the steps below.

<Tabs.Container defaultValue="TypeScript">
<Tabs.List>
<Tabs.Item value="TypeScript">TypeScript</Tabs.Item>
<Tabs.Item value="JavaScript">JavaScript</Tabs.Item>
</Tabs.List>
<Tabs.Panel value="TypeScript">
<VitePolyfillTS />
</Tabs.Panel>
<Tabs.Panel value="JavaScript">
<VitePolyfill />
</Tabs.Panel>
</Tabs.Container>

> If you are still having issues, please see comments on the following issue for additional [Vite workarounds](https://github.com/aws-amplify/amplify-js/issues/9639). Note that there is active ongoing work to make these modifications unnecessary.
## Webpack

### Webpack 5+: `Uncaught ReferenceError: process is not defined`
Expand Down Expand Up @@ -229,31 +270,3 @@ Follow the instructions below if you are using Webpack 5:

Follow [here](#cra-4-cant-import-the-named-export-amplify-from-non-ecmascript-module-only-default-export-is-available) for solutions.


## Vite

### `Uncaught ReferenceError: global is not defined`

<Message
variation="filled"
colorTheme="info"
>
Note: this issue was fixed in `aws-amplify` version 6
</Message>

When working with a [Vite](https://vitejs.dev) project you must make a few modifications. Please follow the steps below.

<Tabs.Container defaultValue="TypeScript">
<Tabs.List>
<Tabs.Item value="TypeScript">TypeScript</Tabs.Item>
<Tabs.Item value="JavaScript">JavaScript</Tabs.Item>
</Tabs.List>
<Tabs.Panel value="TypeScript">
<VitePolyfillTS />
</Tabs.Panel>
<Tabs.Panel value="JavaScript">
<VitePolyfill />
</Tabs.Panel>
</Tabs.Container>

> If you are still having issues, please see comments on the following issue for additional [Vite workarounds](https://github.com/aws-amplify/amplify-js/issues/9639). Note that there is active ongoing work to make these modifications unnecessary.

0 comments on commit dcb3251

Please sign in to comment.