node-serialport: A dynamic link library (DLL) initialization routine failed

SerialPort version:latest NodeJS Version:7.0.0 Operating System and Hardware Platform:win10 Are you using an alternative NodeJS runtime? (eg Electron):electron

Summary of Problem

When I run the electron, throw such as error!

Steps and Code to Reproduce the Issue

the code:

var SerialPort = require("serialport").SerialPort;
var portName = 'COM1';
var serialPort = new SerialPort(portName, {
  baudRate: 9600,
  dataBits: 8,
  parityL:'none',
  stopBits: 1,
  flowControl: false
}, false);
serialPort.list(function (err, ports) {
  ports.forEach(function(port) {
    console.log(port.comName);
    console.log(port.pnpId);
    console.log(port.manufacturer);
  });
});

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (4 by maintainers)

Most upvoted comments

@datamweb

  1. export that env_variables if you use linux. or use set in windows.
  2. use npm install serialport --save

or use this .bat file in windows,make sure you can build in nodejs before

:: Electron 的版本。
set npm_config_target=1.7.9
:: Electron 的系统架构, 值为 ia32 或者 x64。
set npm_config_arch=x64
set npm_config_target_arch=x64
:: 下载 Electron 的 headers。
set npm_config_disturl=https://atom.io/download/electron
:: 告诉 node-pre-gyp 是为 Electron 构建。
set npm_config_runtime=electron
:: 告诉 node-pre-gyp 从源代码构建模块。
set npm_config_build_from_source=true


set PYTHON=D:\Python27
set path=C:\Windows\Microsoft.NET\Framework64\v4.0.30319;%path%


npm install serialport --save

@Caumaker @Quzal @datamweb

a easy way to do

export npm_config_target=1.2.3
export npm_config_arch=x64
export npm_config_target_arch=x64
export npm_config_disturl=https://atom.io/download/electron
export npm_config_runtime=electron
export npm_config_build_from_source=true

if Windows , export use set, like set npm_config_target=1.2.3

target is electron version

and then

npm install serialport --save

good luck