<?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: Lavz</title>
    <description>The latest articles on DEV Community by Lavz (@1lavz).</description>
    <link>https://dev.to/1lavz</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1576183%2F16909571-5503-46e5-8fa2-913ca8e26405.jpg</url>
      <title>DEV Community: Lavz</title>
      <link>https://dev.to/1lavz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/1lavz"/>
    <language>en</language>
    <item>
      <title>Setting Up a React + TypeScript + JEST Project with Create React App (No Headaches!)</title>
      <dc:creator>Lavz</dc:creator>
      <pubDate>Sun, 02 Feb 2025 15:55:29 +0000</pubDate>
      <link>https://dev.to/1lavz/setting-up-a-react-typescript-jest-project-with-create-react-app-no-headaches-1p8m</link>
      <guid>https://dev.to/1lavz/setting-up-a-react-typescript-jest-project-with-create-react-app-no-headaches-1p8m</guid>
      <description>&lt;p&gt;When I decided to start a new React project with TypeScript and Jest, I thought it would be as simple as running &lt;code&gt;npx create-react-app my-app --template typescript&lt;/code&gt; and diving right into coding. Boy, was I wrong! 😅&lt;/p&gt;

&lt;p&gt;I ran into some library version conflicts and had to tweak a few configurations before everything worked smoothly. To save you from the same frustration, I’m sharing my step-by-step setup process. If you’re in a hurry, you can skip to the end and clone the &lt;a href="https://github.com/1LAvz/React-with-TypeScript-Jest" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; with the initial project setup.&lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 1: Create the React App with TypeScript
&lt;/h3&gt;

&lt;p&gt;Run the following command to create your React app with TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app my-app --template typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;While this runs, go grab a coffee ☕️—it might take a few minutes.&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Resolve Dependency Conflicts
&lt;/h3&gt;

&lt;p&gt;At the time of writing, &lt;code&gt;create-react-app&lt;/code&gt; installs React version &lt;code&gt;^19.0.0&lt;/code&gt;, which caused a dependency conflict with &lt;code&gt;@testing-library/react@13.4.0&lt;/code&gt;. The error looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.0.0" from @testing-library/react@13.4.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could downgrade React and React DOM to version 18 to fix this, but I decided to stick with version 19. Here’s how I made it work:&lt;/p&gt;

&lt;p&gt;Ensure &lt;code&gt;react&lt;/code&gt; and &lt;code&gt;react-dom&lt;/code&gt; are both set to version &lt;code&gt;19.0.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Install the necessary dependencies with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i --save-dev @testing-library/react@16.2.0 @types/react @types/react-dom @types/jest @testing-library/jest-dom @babel/plugin-proposal-private-property-in-object
npm i --save web-vitals@4.2.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Configure &lt;code&gt;tsconfig.json&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;tsconfig.json&lt;/code&gt; file in the root folder with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "compilerOptions": {
        "target": "ESNext",
        "module": "ESNext",
        "lib": ["DOM", "ESNext"],
        "jsx": "react-jsx",
        "strict": true,
        "moduleResolution": "Node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "types": ["react-scripts", "jest"],
        "allowSyntheticDefaultImports": true
    },
    "include": ["src"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration ensures TypeScript works seamlessly with React and Jest.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Update &lt;code&gt;reportWebVitals.ts&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you’re using &lt;code&gt;web-vitals@4.2.4&lt;/code&gt;, you’ll need to update the &lt;code&gt;reportWebVitals.ts&lt;/code&gt; file (inside src folder). Replace its content with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { onCLS, onFCP, onLCP, onTTFB } from "web-vitals";

const reportWebVitals = (onPerfEntry?: (metric: any) =&amp;gt; void) =&amp;gt; {
    if (onPerfEntry &amp;amp;&amp;amp; onPerfEntry instanceof Function) {
        onCLS(onPerfEntry);
        onFCP(onPerfEntry);
        onLCP(onPerfEntry);
        onTTFB(onPerfEntry);
    }
};

export default reportWebVitals;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: You’re All Set! 🎉
&lt;/h3&gt;

&lt;p&gt;Now you’re ready to start coding! To run your application, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And to run your tests, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  GitHub Repository
&lt;/h4&gt;

&lt;p&gt;If you want to skip all the setup and dive right into the code, you can clone the repository here:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/1LAvz/React-with-TypeScript-Jest" rel="noopener noreferrer"&gt;GitHub Repo: React with TypeScript and Jest&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Final Thoughts
&lt;/h4&gt;

&lt;p&gt;Setting up a React + TypeScript project isn’t always as straightforward as it seems, especially when dealing with dependency conflicts. But once you’ve got everything configured, it’s smooth sailing from there. I hope this guide saves you some time and frustration!&lt;/p&gt;

&lt;p&gt;If you have any questions or run into issues, feel free to leave a comment below. Happy coding! 🚀&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>jest</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
