MadLittleMods / node-usb-detection

List USB devices in system and detect changes on them.
MIT License
371 stars 114 forks source link

`gyp: name 'openssl_fips' is not defined` - `node-gyp` error #163

Open phhoef opened 2 years ago

phhoef commented 2 years ago

I am trying to re-compile usb-detection on an Apple M1 Mac. Unfortunately, I do get a error

 ⨯ cannot execute  cause=exit status 1
                    errorOut=npm ERR! code 1
    npm ERR! path /Users/me/Documents/Client/node_modules/usb-detection
    npm ERR! command failed
    npm ERR! command sh -c prebuild-install || node-gyp rebuild
    npm ERR! prebuild-install WARN install No prebuilt binaries found (target=11.5.0 runtime=electron arch=arm64 libc= platform=darwin)
    npm ERR! gyp info it worked if it ends with ok
    npm ERR! gyp info using node-gyp@8.4.1
    npm ERR! gyp info using node@17.6.0 | darwin | arm64
    npm ERR! gyp info find Python using Python version 3.9.10 found at "/opt/homebrew/opt/python@3.9/bin/python3.9"
    npm ERR! gyp info spawn /opt/homebrew/opt/python@3.9/bin/python3.9
    npm ERR! gyp info spawn args [
    npm ERR! gyp info spawn args   '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
    npm ERR! gyp info spawn args   'binding.gyp',
    npm ERR! gyp info spawn args   '-f',
    npm ERR! gyp info spawn args   'make',
    npm ERR! gyp info spawn args   '-I',
    npm ERR! gyp info spawn args   '/Users/me/Documents/Client/node_modules/usb-detection/build/config.gypi',
    npm ERR! gyp info spawn args   '-I',
    npm ERR! gyp info spawn args   '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
    npm ERR! gyp info spawn args   '-I',
    npm ERR! gyp info spawn args   '/Users/me/.electron-gyp/11.5.0/include/node/common.gypi',
    npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
    npm ERR! gyp info spawn args   '-Dvisibility=default',
    npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/me/.electron-gyp/11.5.0',
    npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp',
    npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/me/.electron-gyp/11.5.0/<(target_arch)/node.lib',
    npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/me/Documents/Client/node_modules/usb-detection',
    npm ERR! gyp info spawn args   '-Dnode_engine=v8',
    npm ERR! gyp info spawn args   '--depth=.',
    npm ERR! gyp info spawn args   '--no-parallel',
    npm ERR! gyp info spawn args   '--generator-output',
    npm ERR! gyp info spawn args   'build',
    npm ERR! gyp info spawn args   '-Goutput_dir=.'
    npm ERR! gyp info spawn args ]
    npm ERR! gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp
    npm ERR! gyp ERR! configure error 
    npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
    npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:259:16)
    npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
    npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
    npm ERR! gyp ERR! System Darwin 21.3.0
    npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node/17.6.0/bin/node" "/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
    npm ERR! gyp ERR! cwd /Users/me/Documents/Client/node_modules/usb-detection
    npm ERR! gyp ERR! node -v v17.6.0
    npm ERR! gyp ERR! node-gyp -v v8.4.1
    npm ERR! gyp ERR! not ok

Anybody can think how to workaround this?

MadLittleMods commented 2 years ago

Related to https://github.com/MadLittleMods/node-usb-detection/issues/141

phhoef commented 2 years ago

Can you think of any workaround? The error above is thrown, when running electron-builder install-app-deps. When running with --arch x64 flag it is working. The app will also work, when packaged as I am also packaging for x64. But in dev mode, it even won't start as the native dependency is built for the wrong architecture. Is there a way to start start in dev mode with x64?

MadLittleMods commented 2 years ago

I don't know @phhoef 🙇

donovanhiland commented 2 years ago

FWIW I worked through a similar issue while setting up builds in CI for windows. After googling around I found that the specific error you mentioned relating to openssl_fips has something to do with Node 17 not including some configuration by default any more. Downgrading to 16 worked as a temporary fix:

https://github.com/nodejs/node-gyp/issues/2534 https://github.com/marktext/marktext/issues/2812

MadLittleMods commented 1 year ago

@todbot what node-gyp PR fixed this?

It looks like node-gyp@^8.4.0 includes this potential fix https://github.com/nodejs/node-gyp/pull/2497 mentioned in https://github.com/nodejs/node-gyp/issues/2534#issuecomment-954978227

But I can see that @phhoef was reproducing with node-gyp@8.4.1 which came after.


In terms of workarounds I see,

I did not want to edit the binding.gyp file of a module that I was using. So I solved this problem by passing --openssl_fips='' into the script I want to use, like npm install --openssl_fips=''

-- https://github.com/nodejs/node-gyp/issues/2673#issuecomment-1196931379

Or modifying binding.gyp to make the same change.

lukedar commented 1 year ago

@MadLittleMods @phhoef seem like this is not exclusively an M1 issue. I get the same error on intel core i5 running node16`

errorOut=prebuild-install warn This package does not support N-API version 4.2.12
    prebuild-install warn install No prebuilt binaries found (target=4.2.12 runtime=napi arch=x64 libc= platform=darwin)
    gyp info it worked if it ends with ok
    gyp info using node-gyp@9.1.0
    gyp info using node@16.19.1 | darwin | x64
    gyp info find Python using Python version 3.9.6 found at "/Library/Developer/CommandLineTools/usr/bin/python3"
    gyp info spawn /Library/Developer/CommandLineTools/usr/bin/python3
    gyp info spawn args [
    gyp info spawn args   '/Users/lukedarham/.nvm/versions/node/v16.19.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
    gyp info spawn args   'binding.gyp',
    gyp info spawn args   '-f',
    gyp info spawn args   'make',
    gyp info spawn args   '-I',
    gyp info spawn args   '/Users/lukedarham/Documents/apps/idoru-desktop/node_modules/drivelist/build/config.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   '/Users/lukedarham/.nvm/versions/node/v16.19.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   '/Users/lukedarham/.electron-gyp/4.2.12/include/node/common.gypi',
    gyp info spawn args   '-Dlibrary=shared_library',
    gyp info spawn args   '-Dvisibility=default',
    gyp info spawn args   '-Dnode_root_dir=/Users/lukedarham/.electron-gyp/4.2.12',
    gyp info spawn args   '-Dnode_gyp_dir=/Users/lukedarham/.nvm/versions/node/v16.19.1/lib/node_modules/npm/node_modules/node-gyp',
    gyp info spawn args   '-Dnode_lib_file=/Users/lukedarham/.electron-gyp/4.2.12/<(target_arch)/node.lib',
    gyp info spawn args   '-Dmodule_root_dir=/Users/lukedarham/Documents/apps/idoru-desktop/node_modules/drivelist',
    gyp info spawn args   '-Dnode_engine=v8',
    gyp info spawn args   '--depth=.',
    gyp info spawn args   '--no-parallel',
    gyp info spawn args   '--generator-output',
    gyp info spawn args   'build',
    gyp info spawn args   '-Goutput_dir=.'
    gyp info spawn args ]
    gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp
    gyp ERR! configure error
    gyp ERR! stack Error: `gyp` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onCpExit (/Users/lukedarham/.nvm/versions/node/v16.19.1/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:284:16)
    gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
    gyp ERR! System Darwin 21.6.0
    gyp ERR! command "/Users/lukedarham/.nvm/versions/node/v16.19.1/bin/node" "/Users/lukedarham/.nvm/versions/node/v16.19.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
    gyp ERR! cwd /Users/lukedarham/Documents/apps/idoru-desktop/node_modules/drivelist
    gyp ERR! node -v v16.19.1
    gyp ERR! node-gyp -v v9.1.0
    gyp ERR! not ok
error Command failed with exit code 1.`

Do you guys find a fix for this? Im really stuck and not sure where to go from here.
phhoef commented 1 year ago

No, I didn't found a solution for that problem. My workaround is to remove usb-detection as dependency. I am using serialport for communication. I build a timer, that polls every few seconds for new devices through the serialport lib.

lukedar commented 1 year ago

Thanks for your reply. Do you mind sharing your code so there is an alternative on this thread.

phhoef commented 1 year ago

The code is part of a bigger application, but I am trying to post the relevant code snips. I am using redux as state container.

I've also a button where the user can manually trigger a refresh of the serial port. So, the redux part was already in place, I've just added the timer as workaround. redux action:

export const getSerialports = () => async (dispatch) =>
{
  const ports = await serialport.list();
  dispatch({
    type: SerialportTypeKeys.GET_SERIAL_PORTS,
    ports
  });
}

redux reducer: The reducer also preselects the first found serial port, if the user hasn't select one...

  switch (action.type) {
    case SerialportTypeKeys.GET_SERIAL_PORTS:
      if (action.ports.length > 0) {
        const selectedPort =
          state.selectedPort === null
            ? action.ports[0]
            : action.ports.find((p) => p.path === state.selectedPort.path);
        return { ...state, ports: action.ports, selectedPort };
      } else return { ...state, ports: action.ports, selectedPort: null };
}

In my index.tsx I am calling the timer:

const store = configureStore();
const boundActions = bindActionCreators({ getSerialports }, store.dispatch);

let lastPorts = [];
const checkSerialPorts = async () => {
  const ports = await SerialPort.list();
  if (!equalPorts(lastPorts, ports)) boundActions.getSerialports();

  lastPorts = ports;
  setTimeout(checkSerialPorts, 2000);
};
checkSerialPorts();

I need to make this binding to the store, as I want to call the redux action. You probably can reduce the complexity and only use the checkSerialPorts() method.

I also needed a proper equals check to determine if an update of the available ports is necessary. Otherwise I would flood my redux store with unnecessary changes ...

export const equalPorts = (a: IPort[], b: IPort[]) => {
  return (
    Array.isArray(a) &&
    Array.isArray(b) &&
    a.length === b.length &&
    a.every((val, index) => val.path === b[index].path)
  );
};

Hope this helps 🙂

lukedar commented 1 year ago

Thank you very much

On Fri, Mar 3, 2023 at 11:06 AM ph @.***> wrote:

The code is part of a bigger application, but I am trying to post the relevant code snips. I am using redux as state container.

I've also a button where the user can manually trigger a refresh of the serial port. So, the redux part was already in place, I've just added the timer as workaround. redux action:

export const getSerialports = () => async (dispatch) => {

const ports = await serialport.list();

dispatch({

type: SerialportTypeKeys.GET_SERIAL_PORTS,

ports

}); }

redux reducer: The reducer also preselects the first found serial port, if the user hasn't select one...

switch (action.type) {

case SerialportTypeKeys.GET_SERIAL_PORTS:

  if (action.ports.length > 0) {

    const selectedPort =

      state.selectedPort === null

        ? action.ports[0]

        : action.ports.find((p) => p.path === state.selectedPort.path);

    return { ...state, ports: action.ports, selectedPort };

  } else return { ...state, ports: action.ports, selectedPort: null };

}

In my index.tsx I am calling the timer:

const store = configureStore(); const boundActions = bindActionCreators({ getSerialports }, store.dispatch);

let lastPorts = []; const checkSerialPorts = async () => {

const ports = await SerialPort.list();

if (!equalPorts(lastPorts, ports)) boundActions.getSerialports();

lastPorts = ports;

setTimeout(checkSerialPorts, 2000); }; checkSerialPorts();

I need to make this binding to the store, as I want to call the redux action. You probably can reduce the complexity and only use the checkSerialPorts() method.

I also needed a proper equals check to determine if an update of the available ports is necessary. Otherwise I would flood my redux store with unnecessary changes ...

export const equalPorts = (a: IPort[], b: IPort[]) => {

return (

Array.isArray(a) &&

Array.isArray(b) &&

a.length === b.length &&

a.every((val, index) => val.path === b[index].path)

); };

Hope this helps 🙂

— Reply to this email directly, view it on GitHub https://github.com/MadLittleMods/node-usb-detection/issues/163#issuecomment-1453361784, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVPVRUTWUZNGHZPIRB4VBTW2HGDFANCNFSM5PX76JUA . You are receiving this because you commented.Message ID: @.***>

lukedar commented 1 year ago

Unfortunately after trying the serialport module I get the following error.

dyld[50034]: missing symbol called phhoef did you experience this also?

phhoef commented 1 year ago

Sony, not as far as I remember. i typically try to use the pre-builds if possible. probably asking the serialport guys, is a good idea