Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add astro to troubleshooting guide #3410

Merged
merged 7 commits into from
Feb 13, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,53 @@ Webpack 4 already includes this polyfill.
```

## Vite

<Tabs>
<TabItem title="TypeScript">
When working with a [Vite](https://vitejs.dev) project you must make a few modifications. Please follow the steps below.

**1.** Add the following script tag to the `index.html` file at the bottom of the `<body>` tag.
**1.** Add the following script tag to the `index.html` file right before the `</body>` tag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much more explicit!


```html
<script>
window.global = window;
window.process = {
env: { DEBUG: undefined },
}
var exports = {};
</script>
</body>
```

**2.** Update the `vite.config.ts` and add a resolve alias inside the `defineConfig({})` as seen below.

```ts
export default defineConfig({
plugins: [react()],
resolve: {
alias: [
{
find: './runtimeConfig',
replacement: './runtimeConfig.browser',
},
]
}
})
```
**3.** Update the `tsconfig.json` file and add `skipLibCheck: true` under `compilerOptions`.

```json
"compilerOptions": {
"skipLibCheck": true,
}
...
```
</TabItem>
<TabItem title="JavaScript">
When working with a [Vite](https://vitejs.dev) project you must make a few modifications. Please follow the steps below.

**1.** Add the following script tag to the `index.html` file right before the `</body>` tag. This will only run on the client side and will polyfill Node globals.

```html
<script>
window.global = window;
window.process = {
Expand All @@ -56,10 +96,9 @@ When working with a [Vite](https://vitejs.dev) project you must make a few modif
</body>
```

**2.** Update the `vite.config.ts` and add in a resolve object inside the `defineConfig({})` as seen below.
**2.** Update the `vite.config.js` and add a resolve alias inside the `defineConfig({})` as seen below.

```js
...
export default defineConfig({
plugins: [react()],
resolve: {
Expand All @@ -72,7 +111,41 @@ export default defineConfig({
}
})
```
</TabItem>
</Tabs>

## Astro

When working with a [Astro](https://astro.build/) project you must make a few modifications. Please follow the steps below.
<Tabs>
<TabItem title="TypeScript">
**1.** Add the following script to the bottom of the `index.astro` file. This will only run on the client side and will polyfill Node globals.

```html
<script>
window.global = window;
window.process = {
env: { DEBUG: undefined },
} as unknown as NodeJS.Process;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: all astro files are TS files

var exports = {};
</script>
```

**2.** Update the `astro.config.mjs` to add a resolve object inside the `defineConfig({})` as seen below.

```js
export default defineConfig({
plugins: [react()],
resolve: {
alias: [
{
find: './runtimeConfig',
replacement: './runtimeConfig.browser',
},
]
}
})
```
**3.** Update the `tsconfig.json` file and add `skipLibCheck: true` under `compilerOptions`.

```js
Expand All @@ -81,6 +154,38 @@ export default defineConfig({
"skipLibCheck": true,
...
```
</TabItem>
<TabItem title="JavaScript">
**1.** Add the following script to the bottom of the `index.astro` file. This will only run on the client side and will polyfill Node globals.

```html
<script>
window.global = window;
window.process = {
env: { DEBUG: undefined },
}
var exports = {};
</script>
```

**2.** Update the `astro.config.mjs` to add in a resolve object inside the `defineConfig({})` as seen below.
reesscot marked this conversation as resolved.
Show resolved Hide resolved

```js
export default defineConfig({
plugins: [react()],
resolve: {
alias: [
{
find: './runtimeConfig',
replacement: './runtimeConfig.browser',
},
]
}
})
```
</TabItem>
</Tabs>


## Create React App

Expand Down