carsten-klaffke / send-intent

Repository for send-intent Capacitor plugin
MIT License
106 stars 12 forks source link

sveltekit vite ^3.0.0 #55

Closed joejarlett closed 1 year ago

joejarlett commented 2 years ago

Describe the bug

Hi, I updated my sveltekit to work with https://github.com/CodetrixStudio/CapacitorGoogleAuth which had a dependency of "vite": "^3.0.0" Now the send-intent module module fails to import with the following error. Any pointers would be much appreciated. Many thanks, Joe

(node:11444) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. (Use node --trace-warnings ... to show where the warning was created) Cannot use import statement outside a module C:\Users\joe\Documents\web\my-app2\node_modules\send-intent\dist\esm\index.js:1 import { registerPlugin } from "@capacitor/core"; ^^^^^^

SyntaxError: Cannot use import statement outside a module at Object.compileFunction (node:vm:352:18) at wrapSafe (node:internal/modules/cjs/loader:1033:15) at Module._compile (node:internal/modules/cjs/loader:1069:27) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at ModuleWrap. (node:internal/modules/esm/translators:170:29) at ModuleJob.run (node:internal/modules/esm/module_job:198:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:385:24)

However, It works with "vite": "^2.9.13"

To Reproduce npm create svelte my-app cd my-app yarn install yarn add @capacitor/core @capacitor/cli send-intent

update index file to import send-intent // .\src\routes\index.svelte

<script lang="ts">
    import { SendIntent } from "send-intent";
</script>

Expected behavior

The compiling error prevents the page from loading

Desktop (please complete the following information):

carsten-klaffke commented 2 years ago

Hey @joejarlett, please try adding type="module" to your script tag! Best regards Carsten

Fabianofski commented 5 months ago

I had the same issue and fixed it by adding this to my vite.config.ts

export default defineConfig({
    // ...
       ssr: {
           noExternal: ['send-intent']
       }
});