caoxiemeihao / electron-vite-samples

Electron⚡️Vite samples, includes C/C++ addons | 样板代码集合,包含 C/C++ 扩展
MIT License
190 stars 26 forks source link

Class extends value undefined is not a constructor or null #13

Open CoderWeiJ opened 9 months ago

CoderWeiJ commented 9 months ago

你好,我按照教程配置了serialport,但是提示类继承了空的,看源码好像是require导入的stream模块识别不到

image image

// vite.config.ts
import { defineConfig } from "vite";
import path from "node:path";
import electron from "vite-plugin-electron/simple";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    electron({
      main: {
        // Shortcut of `build.lib.entry`.
        entry: "electron/main.ts",
        vite: {
          build: {
            minify: false,
            rollupOptions: {
              external: ['serialport'],
            },
          },
        },
      },
      preload: {
        // Shortcut of `build.rollupOptions.input`.
        // Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.
        input: path.join(__dirname, "electron/preload.ts"),
      },
    }),
  ],
});
<script setup lang="ts">
import { onMounted } from 'vue';
import { SerialPort } from 'serialport'

onMounted(async () => {
  await SerialPort.list();
})
</script>

<template>
  <div>App.vue</div>
</template>

<style scoped>

</style>
caoxiemeihao commented 7 months ago

代码拉下来就用不了?配置没改过?

CoderWeiJ commented 7 months ago

我是魏健!已收到您的邮件。I'm Wei Jian! We have received your email.