简体   繁体   中英

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

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>
  );
}

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",
  ]
}

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'],
    },
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM