HMS-Core / hms-cordova-plugin

This repo contains all of Cordova HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
88 stars 40 forks source link

'Could not resolve "cordova"' error in Capactior projects with Vite #177

Closed a777med closed 2 weeks ago

a777med commented 2 weeks ago

After installing & importing @hmscore/cordova-plugin-hms-push in a clean Ionic project using Capacitor, Vue.js and Vite, I get this error when trying to run the project for dev:

✘ [ERROR] Could not resolve "cordova"

    node_modules/@hmscore/cordova-plugin-hms-push/www/utils.js:19:26:
      19 │ const cordova_1 = require("cordova");
         ╵                           ~~~~~~~~~

  You can mark the path "cordova" as external to exclude it from the bundle, which will remove this
  error and leave the unresolved path in the bundle. You can also surround this "require" call with
  a try/catch block to handle this failure at run-time instead of bundle-time.

Environment

a777med commented 2 weeks ago

I had to use the plugin like this:

const HmsPush = window.HmsPush

Rather than importing it import HmsPush from "@hmscore/cordova-plugin-hms-push";