[英]Module not found: Error: Can't resolve './App' from React 18 w/TypeScript
Getting this error when trying to upgrade to react 18.尝试升级到 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?
我正在使用 typescript 所以我假设应用程序和索引都必须以 a.tsx 结尾?
Teh app and index file are both within the same folder (src)应用程序和索引文件都在同一个文件夹(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索引.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应用程序.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
尝试将此添加到您的
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
.可能问题出在您的
webpack
中,因为您使用的是Typescript
。 In your webpack try adding ts
and tsx
在您的 webpack 中尝试添加
ts
和tsx
module.exports = {
//Rest of your code
resolve: {
extensions: ['.ts', '.tsx'],
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.