I followed the instructions to create a vite project for Vue3. The method I'm using doesn't create any env.development or env.Production files, so I have little context for reading the documentation. I guess I need something there, but what?
It compiles but fails on the router:
import { createWebHistory, createRouter, RouteRecordRaw } from "vue-router"; const history = createWebHistory(); const routes: Array<RouteRecordRaw> = [ { path: "/", name: "Appointments", component: () => import("../views/Appointments.vue"), }, { path: "/pets", name: "Appointments", component: () => import("../views/Pets.vue"), }, { path: "/Claims", name: "Claims", component: () => import("../views/Claims.vue"), }, ]; const router = createRouter({ //fails on this line: history: createWebHistory(process.env.BASE_URL), routes, }); export default router;
How to set the base URL?
The
.env
files (including.env.development
) must be added manually to your project directory. However, you don't need them to setBASE_URL
becauseBASE_URL
is automatically set from thebase
configuration invite.config .js
Medium:To reference environment variables in the source, use
import.meta.env
instead ofprocess.env
:Demo