部署时我遇到错误,这是Vite + React + Typescript应用程序。
9:27:22 AM: $ tsc && vite build
9:27:23 AM: src/App.tsx(2,23): error TS2307: Cannot find module './components/AppFooter' or its corresponding type declarations.
9:27:23 AM: src/App.tsx(3,23): error TS2307: Cannot find module './components/AppHeader' or its corresponding type declarations.
在我得到错误的地方,appheader和appfooter只包含打印"工作"。
import "./App.css";
import AppFooter from "./components/AppFooter";
import AppHeader from "./components/AppHeader";
function App() {
return (
<>
<AppHeader></AppHeader>
<AppFooter></AppFooter>
</>
);
}
export default App;
我的文件结构:
package.json文件:
{
"name": "vite---react---typescript",
"private": true,
"version": "0.0.0",
"scripts": {
"start": "npx http-server ./dist",
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^1.3.0",
"autoprefixer": "^10.4.13",
"postcss": "^8.4.20",
"tailwindcss": "^3.2.4",
"typescript": "^4.6.3",
"vite": "^2.9.9"
}
}
我试着改变 shell 和文件名,它在我的本地运行得很好,但在我部署时却不是。
1条答案
按热度按时间7gcisfzg1#
您的组件似乎位于./components/main中,因此您需要更新导入的路径,例如: