I’m new to Capacitor and Vite, and plan to migrate my existing Cordova app over. I’m trying to run a trivial app but can’t-- as soon the JavaScript tries import { Filesystem, Directory, Encoding } from "@capacitor/filesystem"the Android studio log shows:
Uncaught TypeError: Failed to resolve module specifier "@capacitor/filesystem".
(I can’t build from the CLI-- running npx cap build android always errs with:
Gradle requires JVM 17 or later to run. Your build is currently configured to use JVM 8.
… even though I’ve configured everything to use JVM 21 everywhere I know about.)
I can’t create a new Capacitor project with npm init @capacitor/app@latest (reported here), so I’m trying to create a trivial app in Cordova then migrate it over to Capacitor.
Here’s the sequence of commands I’ve run:
# create and test demo Cordova app
cordova create test-cap-vite com.jmarshall.testcapvite TestCapacitorVite
cd test-cap-vite
cordova platform add android
cordova emulate android # successfully build and run on emulator
# convert to Capacitor app
npm i @capacitor/core
npm i -D @capacitor/cli
npx cap init
Name: TestCapacitorVite
Package ID: com.jmarshall.testcapvite
Web asset directory: www
npm i @capacitor/android
npx cap add android
npm i @capacitor/filesystem
# edit files, shown below
vi www/index.html www/js/index.js
# install vite
npm install -D vite
# build and sync app files-- is this correct?
npx vite build www
npx cap sync
# this fails with "Gradle requires JVM 17 or later to run. Your build is currently configured to use JVM 8."
npx cap build android
Here’s www/index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
<meta name="color-scheme" content="light dark">
<link rel="stylesheet" href="css/index.css">
<title>Capacitor + Vite test</title>
<script type="module" src="js/index.js"></script>
</head>
<body>
Capacitor + Vite test
</body>
</html>
… and www/js/index.js:
import { Filesystem, Directory, Encoding } from "@capacitor/filesystem";
alert('starting Capacitor app') ;
let lib= await Filesystem.stat({
directory: Directory.Library,
path: '.',
}) ;
alert(lib) ;
Here’s capacitor.config.json:
{
"appId": "com.jmarshall.testcapvite",
"appName": "TestCapacitorVite",
"webDir": "www"
}
If it matters, here’s package.json:
{
"name": "com.jmarshall.testcapvite",
"displayName": "TestCapacitorVite",
"version": "1.0.0",
"description": "A sample Apache Cordova application that responds to the deviceready event.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"ecosystem:cordova"
],
"author": "Apache Cordova Team",
"license": "Apache-2.0",
"devDependencies": {
"@capacitor/cli": "^8.4.2",
"cordova-android": "^15.1.0",
"vite": "^8.1.5"
},
"cordova": {
"platforms": [
"android"
]
},
"dependencies": {
"@capacitor/android": "^8.4.2",
"@capacitor/core": "^8.4.2",
"@capacitor/filesystem": "^8.1.2"
}
}
I can build it in Android Studio (after some Java version yak-shaving), but when it runs it fails on the import statement as described above. index.html loads correctly, but the alerts are never run.
Isn’t Vite suppose to resolve "@capacitor/filesystem"in its build? Capacitor requires a bundler, right?
This is all using the latest versions of almost everything, I believe:
- MacOS 26.5.2 (M1 on Apple Silicon)
- Android Studio Quail 2 | 2026.1.2 Patch 1
- Android emulator for Pixel 7, API 36.1 (the only non-latest version here)
- Capacitor 8.4.2
- Vite 8.1.5
Any ideas why this is failing, and how to fix it? Or, how to investigate further?
Thank you so much for any help! ![]()