This is a super basic template for react js/tailwind v3. What's below is the output from Google's AI studio if you want to make this yourself.
This guide documents the precise, manual process required to create a stable React and Tailwind CSS v3 environment in GitHub Codespaces. It is a record of a successfully debugged session, created to bypass critical issues with npm
installing pre-release software and npx
command failures within the Codespace environment.
This process works because it makes no assumptions. It forces the correct dependency versions and manually creates configuration files to bypass broken tooling.
First, we create a stable, lightweight environment.
-
Start with a new, empty GitHub repository.
-
In that repository, create the file
.devcontainer/devcontainer.json
and add the following content. This ensures you get a clean Node.js environment without the bloat that can cause storage errors.{ "name": "Node.js-Vite-React-Stable", "image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye", "customizations": { "vscode": { "extensions": [ "bradlc.vscode-tailwindcss", "esbenp.prettier-vscode" ] } } }
-
Commit the file and launch the Codespace from your repository's
< > Code
menu.
We will create the Vite project files and then immediately fix the package.json
before installing anything. This is the key to preventing all downstream errors.
-
Once the Codespace is running, a terminal will be open. Create the base React project files in the current directory:
npm create vite@latest . -- --template react
-
DO NOT RUN
npm install
YET. Open thepackage.json
file that was just created. -
Delete the entire
"devDependencies": { ... }
block and replace it with this verified block that forces the stable Tailwind v3 and its compatible dependencies:"devDependencies": { "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "@vitejs/plugin-react": "^4.3.1", "autoprefixer": "^10.4.19", "eslint": "^8.57.0", "eslint-plugin-react": "^7.34.4", "eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-refresh": "^0.4.8", "postcss": "^8.4.39", "tailwindcss": "^3.4.6", "vite": "^5.3.4" }
-
Save the
package.json
file. Now that the correct versions are specified, run the install command. This will download the packages we just defined.npm install
The npx tailwindcss init -p
command repeatedly failed. We will bypass it completely by creating and writing the files ourselves.
- In the terminal, use the
touch
command to create the two empty configuration files:touch tailwind.config.js touch postcss.config.js
- Open the newly created
tailwind.config.js
file from the explorer. Paste the following configuration into it:/** @type {import('tailwindcss').Config} */ export default { content: [ "./index.html", "./src/**/*.{js,ts,jsx,tsx}", ], theme: { extend: {}, }, plugins: [], }
- Open the newly created
postcss.config.js
file. Paste the following configuration into it. This is the correct format for Tailwind v3.export default { plugins: { tailwindcss: {}, autoprefixer: {}, }, }
Tell the application to load the CSS file containing the Tailwind styles.
- Open
src/index.css
. Delete all of its contents and replace them with the three Tailwind directives:@tailwind base; @tailwind components; @tailwind utilities;
- Open
src/main.jsx
. Add the import statement forindex.css
at the top of the file to ensure the styles are loaded by Vite.import React from 'react'; import ReactDOM from 'react-dom/client'; import App from './App.jsx'; import './index.css'; // This line loads the styles ReactDOM.createRoot(document.getElementById('root')).render( <React.StrictMode> <App /> </React.StrictMode>, );
The setup is now complete and correct. Run the development server and use a test component to verify the result.
- In the terminal, run the server:
npm run dev
- When the notification appears, click Open in Browser. You will see the default, unstyled Vite page.
- Now, open
src/App.jsx
. Delete all of its content and replace it with this test code:function App() { return ( <div className="bg-slate-900 min-h-screen flex items-center justify-center font-sans"> <div className="max-w-md mx-auto bg-slate-800 rounded-xl shadow-2xl overflow-hidden p-8 space-y-4"> <div className="text-center"> <h1 className="text-4xl font-bold text-indigo-400"> It Works. </h1> <p className="mt-2 text-lg text-slate-300"> The correct Tailwind v3 styles are now applied. </p> </div> <div className="pt-4"> <button className="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-4 rounded-lg"> Success </button> </div> </div> </div> ) } export default App
- Save the
App.jsx
file. The browser tab should hot-reload and display a fully styled card. This confirms the entire process was successful.