Hi everyone,
I’m building a mobile app using React + Vite + Capacitor. I am using the dist build approach instead of running a development server.
My capacitor.config.ts looks like this:
const config: CapacitorConfig = {
appId: "co.testapp.com",
appName: "Test App",
webDir: "dist"
};
I build the project using:
npm run build
npx cap sync
npx cap run android
The dist folder is generated correctly and contains index.html and assets.
However, when the Android app starts, the WebView shows this error:
Failed to load resource: net::ERR_CONNECTION_REFUSED
Webpage https://localhost could not be loaded
It looks like Capacitor is still trying to load from https://localhost instead of the bundled files.
Things I have already checked:
-
Removed any
server.urlfromcapacitor.config.ts -
Rebuilt the project (
npm run build) -
Ran
npx cap sync -
Cleaned the Android build (
./gradlew clean) -
Confirmed that
dist/index.htmlexists
Expected behavior:
The app should load from capacitor://localhost/index.html.
Has anyone experienced this issue or knows what might cause Capacitor to still attempt loading https://localhost?
Any help would be appreciated.
