Uncaught Error: Cannot find module 'serialport' after packaging electron app (electron-packager)
See original GitHub issueSerialPort version: 4.0.7
NodeJS Version: 6.9.4
Operating System and Hardware Platform: Windows 10 x64, intel core i3-2310M CPU @ 2.10GHz, 4GB RAM
Are you using an alternative NodeJS runtime? (eg Electron): Yes, am using electron
Summary of Problem
Hi, our app uses the node-serialport package. Works fine in development, but on packaging using electron-packager
it fails with the error:
module.js:457 Uncaught Error: Cannot find module 'serialport'
Steps and Code to Reproduce the Issue
- Download starter app [angular2-electron] (https://github.com/joaogarin/angular2-electron). Edit the login page so that you can go directly to home page.
- Install node-serialport
npm install serialport --save - In
home.component.ts, initialize the serialport in the import section:
...
import { Location } from "@angular/common";
declare var require: any
var SerialPort = require('serialport');
...
- Package the electron app using
electron-packagerby running the following commandnpm run package - Go to the new created
releasefolder in the root folder of the app and run the app by double clicking on it.
N/B: I have even tried modifing the package.json script section to:
"scripts": {
...
"package-win": "electron-packager src/app --overwrite --asar=true --platform=win32 --arch=x64 --icon=src/app/dist/assets/app-icon --prune=true --out=release-builds"
}
and
"scripts": {
...
"package-win": "electron-packager src/app --overwrite --asar.unpack=\"node_modules/serialport/build/**\" --asar=true --platform=win32 --arch=x64 --icon=src/app/dist/assets/app-icon --prune=true --out=release-builds"
}
I have tried modifying --asar.unpack to various paths --asar.unpack=\"*.node\" but still not packing the node-serialport. Any pointers on how to package the app using electron-packager and have it run in production. Am yet to make the installer.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
Cannot find module 'serialport' after packaging electron app ...
Hi, our app uses the node-serialport package. Works fine in development, but on packaging using electron-packager it fails with the error:.
Read more >Npm start errors Uncaught Error: Cannot find module 'serialport
I believe you are using the wrong command run the angular application you need to use the following command to run the angular...
Read more >EmergingTechnologyAdvisors/node-serialport - Gitter
I am following the Github and cannot understand why my port.read is just ... my app with electron-packager and open my app I...
Read more >electron-johnny-five-switch-example - npm package - Snyk
An electron app using johnny-five to respond to a switch and turn an led on and ... electron-packager ... Uncaught Error: Cannot find...
Read more >Integrate native Node.js modules into an Electron app (2/2)
package an Electron app into OS-specific bundle ... into this error while running Electron app: Uncaught Error: Could not find module root ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ferrisimo I managed to get it working with
electron-builder. Thank you for the help. This issue may now be closed.Essentially all you need to do is npm install -g electron-builder
Then add to your scripts section…
“scripts”: { “pack”: “build --dir”, “dist”: “build” },
Then a new section below the dependencies which identifies your icons for each target eg
“dependencies”: { … “serialport”: “^4.0.6” }, “build”: { “appId”: “Your App Id”, “mac”: { “icon”: “./app/img/app-icon.icns”, “category”: “Whatever” }, “win”: { “icon”: “./app/img/app-icon.ico”, “iconUrl”: “./app/img/app-icon.ico” } }
Then on window or mac npm run dist to create your EXE under the dist directory.