Home > Enterprise >  Module not found: Error: Can't resolve './App' from React 18 w/TypeScript
Module not found: Error: Can't resolve './App' from React 18 w/TypeScript

Time:05-10

Getting this error when trying to upgrade to react 18.

I wonder if it has to do with my file types? I'm using typescript so I assume both the app and index have to end with a .tsx?

Teh app and index file are both within the same folder (src)

ERROR in ./src/index.tsx 12:0-24

Module not found: Error: Can't resolve './App' in 'C:\Users\CleverlyDone\Documents\GitHub\myProjectName\src'

My files are:

index.tsx


/** Vendor */
import React from "react";

/** Shared CSS */
import "./dist/css/index.css";

/** Entry Point */
import App from "./App";

/** Analytics */
// import reportWebVitals from "./reportWebVitals";

import { createRoot } from "react-dom/client";
const container = document.getElementById("app");
const root = createRoot(container!);
root.render(<App />);

App.tsx

/** Vendor **/
import React from "react";

/** CSS */
import "./dist/css/app.css";

export default function App() {
  return (
      <div>Placeholder</div>
  );
}

CodePudding user response:

Probably problem is in your webpack because you are using Typescript. In your webpack try adding ts and tsx

module.exports = {
    //Rest of your code
    resolve: {
        extensions: ['.ts', '.tsx'],
    },
};

CodePudding user response:

Try adding this to your tsconfig.json


{
  "compilerOptions": {
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src",
  ]
}
  • Related