Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-serialport is not working #42

Closed
4 tasks done
stalkercn opened this issue Oct 24, 2022 · 5 comments
Closed
4 tasks done

node-serialport is not working #42

stalkercn opened this issue Oct 24, 2022 · 5 comments
Labels
question Further information is requested

Comments

@stalkercn
Copy link

Describe the bug

When node-serialport lib is imported, error occurred.

Node Version: 16.18.0
Node-SerialPort Version: 10.4.0
Electron Version: 20.3.3
Vite Version: 3.1.8
Electron-Vite Version: 1.0.11

Reproduction:

  1. install node-serialport
    npm i serialport

  2. code in main/index.ts:
    import { SerialPort } from serialport; console.log(SerialPort)

  3. run electron-vite

Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=107 uv=1 libc=glibc node=16.15.0 electron=20.3.3

Electron-Vite Version

1.0.11

Electron Version

20.3.3

Vite Version

3.1.8

Validations

@stalkercn stalkercn added the bug Something isn't working label Oct 24, 2022
@alex8088
Copy link
Owner

need to externalize serialport, edit your config:

import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
 //...
})

use externalizeDepsPlugin to automatically externalize package.json dependencies.

Learm more about https://evite.netlify.app/guide/build.html#externals

@alex8088 alex8088 added question Further information is requested and removed bug Something isn't working labels Oct 24, 2022
@stalkercn
Copy link
Author

app can be launched now, but when npm i is ran, there's still an error.

electron-builder install-app-deps

• electron-builder version=23.6.0
• loaded configuration file=C:\git\electron-app\electron-builder.yml
• rebuilding native dependencies dependencies=@serialport/bindings-cpp@10.7.0 platform=win32 arch=x64
⨯ cannot execute cause=fork/exec C:\Users\Administrator\AppData\Roaming\npm\node_modules\pnpm\bin\pnpm.cjs: %1 is not a valid Win32 application.
command='C:\Users\Administrator\AppData\Roaming\npm\node_modules\pnpm\bin\pnpm.cjs' rebuild @serialport/bindings-cpp@10.7.0
workingDir=
 ELIFECYCLE  Command failed with exit code 1.

@Taqibrian
Copy link

Taqibrian commented Oct 25, 2022 via email

@alex8088
Copy link
Owner

@stalkercn
Remove "postinstall": "electron-builder install-app-deps" in package.json after successfully installing serialport .

May be some problem in electron-builder install-app-deps rebuilding serialport. serialport/node-serialport#2463

@stalkercn
Copy link
Author

@stalkercn Remove "postinstall": "electron-builder install-app-deps" in package.json after successfully installing serialport .

May be some problem in electron-builder install-app-deps rebuilding serialport. serialport/node-serialport#2463

this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants