quasarframework / quasar

Quasar Framework - Build high-performance VueJS user interfaces in record time
https://quasar.dev
MIT License
25.96k stars 3.52k forks source link

Vite Error No matching export in "src-capacitor/node_modules/@capacitor/core/dist/esm/index.js" for import "registerPlugin" #14424

Open xiangnanscu opened 2 years ago

xiangnanscu commented 2 years ago

What happened?

When I try to use @capacitor/filesystem api like Filesystem.writeFile in .vue file:

import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';

const writeSecretFile2 = async () => {
  await Filesystem.writeFile({
    path: 'secrets/text.txt',
    data: "This is a test",
    directory: Directory.Documents,
    encoding: Encoding.UTF8,
  });
};

I run quasar dev -m capacitor -T android and during the process encounter:

Plugin: quasar:eslint
  File: C:/Users/xn/pan/src/components/ExampleComponent.vue

 App •  LINT OK  • C:/Users/xn/pan/src/components/ExampleComponent.vue

Vite Error, /node_modules/.q-cache/vite/capacitor/deps/@capacitor_filesystem.js?v=f01ca588 optimized info should be defined
X [ERROR] No matching export in "src-capacitor/node_modules/@capacitor/core/dist/esm/index.js" for import "registerPlugin"

    node_modules/@capacitor/filesystem/dist/esm/index.js:1:9:
      1 │ import { registerPlugin } from '@capacitor/core';
        ╵          ~~~~~~~~~~~~~~

21:32:17 [vite] error while updating dependencies:
Error: Build failed with 1 error:
node_modules/@capacitor/filesystem/dist/esm/index.js:1:9: ERROR: No matching export in "src-capacitor/node_modules/@capacitor/core/dist/esm/index.js" for import "registerPlugin"   
    at failureErrorWithLog (C:\Users\xn\pan\node_modules\esbuild\lib\main.js:1621:15)     
    at C:\Users\xn\pan\node_modules\esbuild\lib\main.js:1263:28
    at runOnEndCallbacks (C:\Users\xn\pan\node_modules\esbuild\lib\main.js:1043:63)       
    at buildResponseToResult (C:\Users\xn\pan\node_modules\esbuild\lib\main.js:1261:7)    
    at C:\Users\xn\pan\node_modules\esbuild\lib\main.js:1374:14
    at C:\Users\xn\pan\node_modules\esbuild\lib\main.js:675:9
    at handleIncomingPacket (C:\Users\xn\pan\node_modules\esbuild\lib\main.js:772:9)      
    at Socket.readFromStdout (C:\Users\xn\pan\node_modules\esbuild\lib\main.js:641:7)     
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)

What did you expect to happen?

Should not error

Reproduction URL

https://stackblitz.com/edit/quasarframework-vsuuy9?file=package.json

How to reproduce?

yarn start

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Capacitor Mode

Platforms/Browsers

Android

Quasar info output

PS C:\Users\xn\pan> quasar info command

Operating System - Windows_NT(10.0.19044) - win32/x64
NodeJs - 16.17.0

Global packages
  NPM - 8.15.0
  yarn - 1.22.19
  @quasar/cli - 1.3.2
  @quasar/icongenie - Not installed
  cordova - Not installed

Important local packages
  quasar - 2.8.3 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
  @quasar/app-vite - 1.1.1 -- Quasar Framework App CLI with Vite
  @quasar/extras - 1.15.3 -- Quasar Framework fonts, icons and animations
  eslint-plugin-quasar - Not installed
  vue - 3.2.39 -- The progressive JavaScript framework for building modern web UI.
  vue-router - 4.1.5
  pinia - Not installed
  vuex - Not installed
  vite - 2.9.15 -- Native-ESM powered web dev build tool
  eslint - 8.23.1 -- An AST-based pattern checker for JavaScript.
  electron - Not installed
  electron-packager - Not installed
  electron-builder - Not installed
  register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
  @capacitor/core - 2.5.0 -- Capacitor: cross-platform mobile apps with the web
  @capacitor/cli - 2.5.0 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/android - 2.5.0 -- Capacitor: cross-platform mobile apps with the web
  @capacitor/ios - Not installed

Quasar App Extensions
  *None installed*

Networking
  Host - win10
  vEthernet (Default Switch) - 172.21.160.1
  vEthernet (WSL) - 172.18.80.1
  以太网 - 192.168.1.3

Relevant log output

No response

Additional context

No response

jcesarmobile commented 2 years ago

@capacitor/filesystem is meant to be used with Capacitor 3-4, but you are still using @capacitor/core 2.5.0.

Capacitor 2 had the core plugins included, you don't have to install any of the @capacitor/whatever plugins and installing them will fail as it's happening.