Came across this first: Capacitor Network Bug? Problem? Help Me which was close to the error I have but still not able to find a solution.
Problem:
Unable to build for mobile due to errors on mobile build thrown in logcat related to failed module expecting relative paths.
JavaScript Error: {“type”:“js.error”,“error”:{“message”:“Uncaught TypeError: Failed to resolve module specifier "@capacitor/core". Relative references must start with either "/", "./", or "…/".”,“url”:“https://www.testapp.com/“,“line”:0,“col”:0,“errorObject”:”{}”}}
What is working:
The web version builds and works with the exception that in order for it to work, I had to add paths to rollup config below, else it would fail.
paths: { ‘@capacitor/core’: ‘…/…/…/node_modules/@capacitor/core/dist/index.js’ },
What else have I tried:
Copying the node_modules folder to the android build folder and trying to build with that there and also modifying the path resulted in a warning stating flatDir should be avoided because it doesn’t support any meta-data formats. And ask :app:mergeDebugAssets FAILED
ERROR: [public/node_modules/levelup/node_modules/semver/semver.browser.js] Resource and asset merger: Duplicate resources.
Development Environment:
VSC: Version: 1.97.2
Iconic dashboard plugin
Node: 23.9.0
OSX Sonoma 14.4
Android Studio Meercat - 2024.3.1
Physical Android Device
“@capacitor/cli”: “^7.0.1”,
“@capacitor/android”: “^7.0.1”,
“@capacitor/core”: “^7.0.1”,
“@capacitor/ios”: “^7.0.1”,
Folder structure:
Capacitor.config.json
{
“appId”: “com.testapp.app”,
“appName”: “Testapp”,
“webDir”: “dist”,
“server”: {
“hostname”: “www.testapp.com”,
“androidScheme”: “https”
}
}
I have some red folders in my project as well:
node_modules
-@capacitor
android
-app
- capacitor-cordova-android-plugins
Capacitor doctor reports ok
Expected result
To be able to build for web and mobile as well without the above errors thrown