<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akira Abe</title>
    <description>The latest articles on DEV Community by Akira Abe (@akiraabe).</description>
    <link>https://dev.to/akiraabe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F874505%2F3d14255c-acca-4388-b094-76bbbccb060d.jpeg</url>
      <title>DEV Community: Akira Abe</title>
      <link>https://dev.to/akiraabe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akiraabe"/>
    <language>en</language>
    <item>
      <title>Vite+React+Amplify initial setup!</title>
      <dc:creator>Akira Abe</dc:creator>
      <pubDate>Wed, 12 Oct 2022 11:34:03 +0000</pubDate>
      <link>https://dev.to/akiraabe/vitereactamplify-initial-setup-5hn7</link>
      <guid>https://dev.to/akiraabe/vitereactamplify-initial-setup-5hn7</guid>
      <description>&lt;h2&gt;
  
  
  Purpose of this article.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;I want to try out the very fast build tool &lt;a href="https://ja.vitejs.dev/" rel="noopener noreferrer"&gt;Vite&lt;/a&gt;!&lt;/strong&gt; &lt;br&gt;
I wanted to know how to start a project with my usual React+Amplify configuration.&lt;br&gt;
This is my personal note.&lt;/p&gt;

&lt;h2&gt;
  
  
  Software versions
&lt;/h2&gt;

&lt;p&gt;The main software versions are listed below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;node v18.9.0&lt;/li&gt;
&lt;li&gt;TypeScript 4.6.4&lt;/li&gt;
&lt;li&gt;Vite 3.1.0&lt;/li&gt;
&lt;li&gt;React 18.2.0&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary ahead of time
&lt;/h2&gt;

&lt;p&gt;The official Amplify page guides how to use create-react-app when linking Amplify and React.&lt;br&gt;
When using Vite, there are some parts that do not work as they are, so it is necessary to deal with errors.&lt;br&gt;
This section outlines the errors and how to handle them. (Details are described below).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;amplify pull&lt;/code&gt; gives me an error
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

✖ There was an error initializing your environment.
Failed to pull the backend.
🛑 Must use import to load ES Module: /Users/xxxxxxxx/my_first_vite/src/aws-exports.js
require() of ES modules is not supported.
require() of /Users/xxxxxxxx/my_first_vite/src/aws-exports.js from /snapshot/repo/build/node_modules/amplify-frontend-javascript/lib/frontend-config-creator.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We need to treat this error like this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rename aws-exports.js to aws-exports.ts&lt;/li&gt;
&lt;li&gt;Remove the line "type": "module" from package.json&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Additional Info.&lt;/strong&gt;&lt;br&gt;
I got a message from Discord community, below!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For what it's worth, the ESM issue (where we have to remove "type": "module") is fixed with the latest version version of the CLI, 10.2.3&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Error with &lt;code&gt;yarn dev&lt;/code&gt;.
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Uncaught ReferenceError: global is not defined


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The following actions will be taken&lt;br&gt;
Change index.html&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;amplify publish&lt;/code&gt; causes error
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

2: import { ProviderError } from "@aws-sdk/property-provider";
3: import { Buffer } from "buffer";
4: import { request } from "http";
            ^
5: /**
6:  * @internal
error during build:
Error: 'request' is not exported by __vite-browser-external, imported by node_modules/@aws-sdk/credential-provider-node/node_modules/@aws-sdk/credential-provider-imds/dist/es/remoteProvider/httpRequest.js


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Change vite.config.ts&lt;/p&gt;

&lt;h2&gt;
  
  
  Development Procedure
&lt;/h2&gt;

&lt;p&gt;Assuming that node, AmplifyCLI, and Vite have already been installed, we will start with project creation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a React project using Vite&lt;/li&gt;
&lt;li&gt;Create an Amplify project&lt;/li&gt;
&lt;li&gt;Initialize the app&lt;/li&gt;
&lt;li&gt;Do the data model integration&lt;/li&gt;
&lt;li&gt;Hosting with Amplify CLI&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create a React project using Vite
&lt;/h3&gt;

&lt;p&gt;The commands are as follows.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

yarn create vite my_first_vite &lt;span class="nt"&gt;--template&lt;/span&gt; react-ts


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;"my_first_vite" is the name of the project, and can be any value you wish.&lt;br&gt;
--template react-ts applies the React TypeScript template.&lt;br&gt;
Please also read the official website &lt;a href="https://vitejs.dev/guide/#scaffolding-your-first-vite-project" rel="noopener noreferrer"&gt;[1]&lt;/a&gt;, which explains this command.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating an Amplify project
&lt;/h3&gt;

&lt;p&gt;There are multiple ways to create an Amplify project, but here we will use AmplifyStudio.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating a project in the AWS Management Console
&lt;/h4&gt;

&lt;p&gt;First, select AWS Amplify (hereafter referred to as Amplify) from the AWS Management Console and click&lt;br&gt;
Select [New app]&amp;gt;[Build an app] from the upper right corner of the screen as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ae9trmszcasvtchk4bn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ae9trmszcasvtchk4bn.png" alt="Amplify Studio new app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, enter the App name on the following screen and click "Confirm deployment".&lt;br&gt;
In this case, the name is "my_first_vite", but you can use any name you like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzbzrrwlinh1lo2uf3y5y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzbzrrwlinh1lo2uf3y5y.png" alt="Confirm deployment"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The figure below shows the waiting screen during deployment. （It takes 5 to 6 minutes.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4t4cqet6wt3rv0n54x89.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4t4cqet6wt3rv0n54x89.png" alt="now deploy is going."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When the screen transitions to the following, click "Launch Studio" to launch Amplify Studio.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhabdjl11f8hoj274zpwf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhabdjl11f8hoj274zpwf.png" alt="Now let's launch the studio"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  What to do after launching Amplify Studio
&lt;/h4&gt;

&lt;p&gt;Amplify Studio allows you to configure various backend resources.&lt;br&gt;
It is not the purpose of this article to introduce them in detail, so we will only define a simple data model here.&lt;br&gt;
Other things can be done, such as generating a UI in conjunction with Figma or using Cognito to incorporate authentication, but please refer to another article &lt;a href="https://qiita.com/akiraabe/items/55f28fe4f721f74eb992" rel="noopener noreferrer"&gt;[2]&lt;/a&gt; or the AWS tutorial &lt;a href="https://aws.amazon.com/jp/blogs/news/aws-amplify-studio-figma-to-fullstack-react-app-with-minimal-programming/" rel="noopener noreferrer"&gt;[3]&lt;/a&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  Defining the Data Model
&lt;/h5&gt;

&lt;p&gt;Define the data model as follows. When you are done, press [Save and Deploy].&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzh4s6fwpygimleqzzz84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzh4s6fwpygimleqzzz84.png" alt="Let's launch data model view"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the screen waiting to be deployed. This process will take some time because AppSync and DynamoDB will be created by CloudFormation at this time. (It may take about 10 minutes).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwk8zf4ldg8upoa8repz5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwk8zf4ldg8upoa8repz5.png" alt="deploy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a deployment is complete (successful), you will be taken to the following screen. (Press "Done" to close the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo028wxlvud47t4zfprc8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo028wxlvud47t4zfprc8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, (2) Update your app code will guide you through an example source code when you select the programming language, model, operation, etc. (This is a simplified version, so please refer to the document [&lt;a href=""&gt;4&lt;/a&gt;] for details. (This is a simplified version, so you should check the documentation &lt;a href="https://docs.amplify.aws/lib/datastore/getting-started/q/platform/js/" rel="noopener noreferrer"&gt;[4]&lt;/a&gt; for details)&lt;/p&gt;

&lt;h4&gt;
  
  
  Pull Amplify materials locally
&lt;/h4&gt;

&lt;p&gt;In the React project created by yarn create, run the amplify pull command as follows.&lt;br&gt;
(Here we are working in the VSCode terminal)&lt;/p&gt;

&lt;p&gt;An error will occur, but how to deal with it is described later.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 amplify pull
? Select the authentication method you want to use: AWS profile

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

? Please choose the profile you want to use default
? Which app are you working on? xxxxxxxxxxxxxx                              
Backend environment 'staging' found. Initializing...
? Choose your default editor: Visual Studio Code
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using react
? Source Directory Path:  src
? Distribution Directory Path: dist *** This is "build" by default, but we have explicitly changed it. ***
? Build Command:  npm run-script build
? Start Command: npm run-script start
✅ GraphQL schema compiled successfully.

Edit your schema at /Users/xxxxxxxx/my_first_vite/amplify/backend/api/myfirstvite/schema.graphql or place .graphql files in a directory at /Users/xxxxxxxx/my_first_vite/amplify/backend/api/myfirstvite/schema
Successfully generated models. Generated models can be found in /Users/xxxxxxxx/my_first_vite/src
? Do you plan on modifying this backend? Yes
⠙ Fetching updates to backend environment: staging from the cloud.✅ GraphQL schema compiled successfully.

Edit your schema at /Users/xxxxxxxx/my_first_vite/amplify/backend/api/myfirstvite/schema.graphql or place .graphql files in a directory at /Users/xxxxxxxx/my_first_vite/amplify/backend/api/myfirstvite/schema
✔ Successfully pulled backend environment staging from the cloud.
✖ There was an error initializing your environment.
Failed to pull the backend.
🛑 Must use import to load ES Module: /Users/xxxxxxxx/my_first_vite/src/aws-exports.js
require() of ES modules is not supported.
require() of /Users/xxxxxxxx/my_first_vite/src/aws-exports.js from /snapshot/repo/build/node_modules/amplify-frontend-javascript/lib/frontend-config-creator.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename aws-exports.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/xxxxxxxx/my_first_vite/package.json.



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;An error occurs.&lt;/strong&gt; So, we will respond according to the message.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rename aws-exports.js to aws-exports.ts. (Note that aws-eports.js is created for each amplify pull, so you need to rename it for each pull.)&lt;/li&gt;
&lt;li&gt;Remove the line "type": "module" from package.json.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "name": "my_first_vite",
  "private": true,
  "version": "0.0.0",
-  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc &amp;amp;&amp;amp; vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@types/react": "^18.0.17",
    "@types/react-dom": "^18.0.6",
    "@vitejs/plugin-react": "^2.1.0",
    "typescript": "^4.6.4",
    "vite": "^3.1.0"
  }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After making the above modifications, rerun &lt;code&gt;amplify pull&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set up the initial configuration of the app
&lt;/h3&gt;

&lt;p&gt;At this point, we will launch the application once.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;## Install dependent modules&lt;/span&gt;
yarn &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# Start the development server&lt;/span&gt;
yarn dev


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The application at this point looks like the following&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7w1w5qpa1wa0hefktayv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7w1w5qpa1wa0hefktayv.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change the application to use Amplify.&lt;/p&gt;

&lt;p&gt;The file to be changed is as follows. (The project root is listed as the starting point)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;package.json&lt;/li&gt;
&lt;li&gt;src/index.css&lt;/li&gt;
&lt;li&gt;src/main.tsx&lt;/li&gt;
&lt;li&gt;src/App.tsx&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Include a diff in package.json. (After making changes, run yarn install.)&lt;/p&gt;

&lt;p&gt;package.json&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "dependencies": {
+    "@aws-amplify/ui-react": "^3.5.4",
+    "aws-amplify": "^4.3.36",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Update index.css with the following&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@import url('https://fonts.googleapis.com/css2?family=Inter:slnt,wght@-10..0,100..900&amp;amp;display=swap');
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
    monospace;
}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;main.tsx below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import React from 'react'
import ReactDOM from 'react-dom/client'
+import { AmplifyProvider } from '@aws-amplify/ui-react';
+import { Amplify } from 'aws-amplify';
import App from './App'
import './index.css'
+import config from './aws-exports';

+Amplify.configure(config);

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
-  &amp;lt;React.StrictMode&amp;gt;
+  &amp;lt;AmplifyProvider
     &amp;lt;App /&amp;gt;
+  &amp;lt;/AmplifyProvider&amp;gt;
-  &amp;lt;/React.StrictMode&amp;gt;
)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;App.tsx below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import type { FC } from 'react';
import { Amplify } from 'aws-amplify';
// eslint-disable-next-line import/extensions
import '@aws-amplify/ui-react/styles.css';
import awsExports from './aws-exports';

Amplify.configure(awsExports);

const App: FC = () =&amp;gt; {
  return (
    &amp;lt;h1&amp;gt;
      Hello Amplify+Vite!
    &amp;lt;/h1&amp;gt;
  );
}

export default App;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;However, when I start the development server in this state (yarn dev), I get the following error&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpc2863ku2wp6mao1ryoe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpc2863ku2wp6mao1ryoe.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We update "index.html" as follows. (list the differences)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;link rel="icon" type="image/svg+xml" href="/vite.svg" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;Vite + React + TS&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="root"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;script type="module" src="/src/main.tsx"&amp;gt;&amp;lt;/script&amp;gt;
+    &amp;lt;script&amp;gt;
+      window.global = window;
+      window.process = {
+        env: { DEBUG: undefined },
+      };
+      var exports = {};
+    &amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The following initial screen will appear in your browser as a result so far.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fab9260oyn5xjlqpt0f49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fab9260oyn5xjlqpt0f49.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Source code at this point
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://github.com/akiraabe/my_first_vite/tree/Initial" rel="noopener noreferrer"&gt;https://github.com/akiraabe/my_first_vite/tree/Initial&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Model Linkage.
&lt;/h3&gt;

&lt;p&gt;Please refer to the source code as it is time-consuming to describe the steps to link with the data model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/akiraabe/my_first_vite/tree/UsingAmplify" rel="noopener noreferrer"&gt;https://github.com/akiraabe/my_first_vite/tree/UsingAmplify&lt;/a&gt;&lt;br&gt;
Only data registration and listing are performed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hosting with Amplify CLI
&lt;/h3&gt;

&lt;p&gt;Follow the steps below for hosting. (The reason I use Amplify CLI instead of AWS Management Console is because I want to install WAF on CloudFront.)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;amplify add hosting&lt;/li&gt;
&lt;li&gt;amplify publish&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  amplify add hosting
&lt;/h4&gt;

&lt;p&gt;Execute the following command.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;p&gt;amplify add hosting&lt;br&gt;
✔ Select the plugin module to execute · Amazon CloudFront and S3&lt;br&gt;
? Select the environment setup: PROD &lt;span class="o"&gt;(&lt;/span&gt;S3 with CloudFront using HTTPS&lt;span class="o"&gt;)&lt;/span&gt;&lt;br&gt;
? hosting bucket name myfirstvite-xxxxxxxxxxxx-hostingbucket&lt;br&gt;
Static webhosting is disabled &lt;span class="k"&gt;for &lt;/span&gt;the hosting bucket when CloudFront Distribution is enabled.&lt;/p&gt;

&lt;p&gt;You can now publish your app using the following &lt;span class="nb"&gt;command&lt;/span&gt;:&lt;br&gt;
Command: amplify publish&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  amplify publish&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;Execute the following command&lt;/p&gt;

&lt;p&gt;However, this will fail and will be corrected later.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;p&gt;amplify publish&lt;/p&gt;

&lt;p&gt;&lt;span class="s1"&gt;'request'&lt;/span&gt; is not exported by __vite-browser-external, imported by node_modules/@aws-sdk/credential-provider-node/node_modules/@aws-sdk/credential-provider-imds/dist/es/remoteProvider/httpRequest.js&lt;br&gt;
file: /Users/xxxxxxxxmy_first_vite/node_modules/@aws-sdk/credential-provider-node/node_modules/@aws-sdk/credential-provider-imds/dist/es/remoteProvider/httpRequest.js:4:9&lt;br&gt;
2: import &lt;span class="o"&gt;{&lt;/span&gt; ProviderError &lt;span class="o"&gt;}&lt;/span&gt; from &lt;span class="s2"&gt;"@aws-sdk/property-provider"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
3: import &lt;span class="o"&gt;{&lt;/span&gt; Buffer &lt;span class="o"&gt;}&lt;/span&gt; from &lt;span class="s2"&gt;"buffer"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
4: import &lt;span class="o"&gt;{&lt;/span&gt; request &lt;span class="o"&gt;}&lt;/span&gt; from &lt;span class="s2"&gt;"http"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br&gt;
            ^&lt;br&gt;
5: /&lt;span class="k"&gt;*&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br&gt;
6:  &lt;span class="k"&gt;&lt;/span&gt; @internal&lt;br&gt;
error during build:&lt;br&gt;
Error: &lt;span class="s1"&gt;'request'&lt;/span&gt; is not exported by __vite-browser-external, imported by node_modules/@aws-sdk/credential-provider-node/node_modules/@aws-sdk/credential-provider-imds/dist/es/remoteProvider/httpRequest.js&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h5&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  error handling&lt;br&gt;
&lt;/h5&gt;

&lt;p&gt;Make the following modifications to vite.config.ts. Then re-run amplify publish.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;br&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@vitejs/plugin-react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="c1"&gt;// &lt;a href="https://vitejs.dev/config/" rel="noopener noreferrer"&gt;https://vitejs.dev/config/&lt;/a&gt;&lt;/span&gt;&lt;br&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;br&gt;
&lt;span class="o"&gt;+&lt;/span&gt;  &lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
&lt;span class="o"&gt;+&lt;/span&gt;    &lt;span class="na"&gt;alias&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;br&gt;
&lt;span class="o"&gt;+&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;find&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./runtimeConfig&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;replacement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./runtimeConfig.browser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
&lt;span class="o"&gt;+&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;find&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;replacement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/src&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
&lt;span class="o"&gt;+&lt;/span&gt;    &lt;span class="p"&gt;],&lt;/span&gt;&lt;br&gt;
&lt;span class="o"&gt;+&lt;/span&gt;  &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;react&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;})&lt;/span&gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Impressions&lt;br&gt;
&lt;/h1&gt;

&lt;p&gt;Vite is comfortable to use because the local development server starts up explosively fast (although the code base is not so big this time).&lt;br&gt;
It does take some initial setup, but I felt it was worth it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Footnotes
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://vitejs.dev/guide/#scaffolding-your-first-vite-project" rel="noopener noreferrer"&gt;[1] Scaffolding your first vite project&lt;/a&gt;&lt;br&gt;
&lt;a href="https://qiita.com/akiraabe/items/55f28fe4f721f74eb992" rel="noopener noreferrer"&gt;[2] AmplifyStudio &amp;amp; Figma&lt;/a&gt;&lt;br&gt;
&lt;a href="https://aws.amazon.com/jp/blogs/news/aws-amplify-studio-figma-to-fullstack-react-app-with-minimal-programming/" rel="noopener noreferrer"&gt;[3] AWS AmplifyStudio Tutorial Blog&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.amplify.aws/lib/datastore/getting-started/q/platform/js/" rel="noopener noreferrer"&gt;[4] Amplify DataStore Docs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>vite</category>
      <category>amplify</category>
    </item>
  </channel>
</rss>
