-
[Vite] 절대경로 설정프로그래밍/React 2024. 1. 3. 14:14
Vite + Typescript 를 사용한 프로젝트에서 절대경로를 설정하는 방법
tsconfg.json 과 vite.config.json 모두 고쳐줘야한다.
>tsconfig.json { "compilerOptions": { "baseUrl": "src", ... "path": { "pages/*": ["pages/*"], "components/*": ["components/*"], } }
아래의 설정을 하지 않아서 경로를 제대로 찾지 못하는 에러가 발생했었음.
import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], resolve: { alias: { pages: "/src/pages", components: "/src/components", firebaseApp: "/src/firebaseApp", }, }, });
에러경고문
[plugin:vite:import-analysis] Failed to resolve import "pages/home" from "src/Router.tsx". Does the file exist?
'프로그래밍 > React' 카테고리의 다른 글
[React] 18버전의 추가된 새로운 기능 (step- 1) (0) 2024.02.17 [React] 고차 컴포넌트 (HOC, High Order Component) (0) 2024.01.20 [React] useState의 동작원리 (0) 2023.12.16 [React] react-hook-form (Basic) (0) 2023.12.08 [React] 새로운 리액트 문서에서 제시하는 9가지 권장 사항 (1) 2023.12.06