Attempting to integrate Capacitor v7 into a vanilla JS application.
My project builds as expected for mobile and desktop using rollup.
However when importing Capacitor to the main entry .js file with
import { Capacitor } from “@capacitor/core”;
then calling isNativePlatform() and throwing an alert if true or false
then calling rollup to build, I’m faced with a warning that I am unable to find a viable workaround for.
This is the warning:
{
code: ‘MISSING_GLOBAL_NAME’,
id: ‘@capacitor/core’,
message: ‘No name was provided for external module “@capacitor/core” in “output.globals” – guessing “core”.’,
names: [ ‘core’ ],
url: ‘Configuration Options | Rollup’
}
I have tried to reference Capacitor directly via ./node_modules/@capacitor/core/types/index but that did not work.
On a mobile device, after built and pushed, all is well and the isNativePlatform alert is called, however for web native builds it throws an error stating it can’t read properties of undefined reading isNativePlatform ( due to the inability for rollup to some how package Capacitor ? )
Inspecting the call from the bundled js output, the code is changed to be
if (core.Capacitor.isNativePlatform()) {
rather than it’s initial implementation of
if (Capacitor.isNativePlatform()) {
I’ve searched around on rollup and the above issue, but have come up empty on a solution.
I’m wondering if anyone here has possibly run into this and if they did, what did they do to get around it?
Thank you.