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

[nodejs] crash when importing bcrypt #15048

Closed
6 of 7 tasks
fauxpark opened this issue Jan 15, 2023 · 17 comments · Fixed by #15372
Closed
6 of 7 tasks

[nodejs] crash when importing bcrypt #15048

fauxpark opened this issue Jan 15, 2023 · 17 comments · Fixed by #15372
Labels

Comments

@fauxpark
Copy link
Contributor

Description / Steps to reproduce the issue

  1. Create a file test.js in a new folder:
    const bcrypt = require('bcrypt')
    bcrypt.hash('hello', 10, (err, hash) => {
      console.log(hash)
    })
  2. Run npm init and install bcrypt
  3. Run node test.js

This is probably not bcrypt-specific, likely a general issue with how Node loads dynamic libraries.

Expected behavior

Hash should be printed.

Actual behavior

Node crashes with the following:

$ node test.js
node:internal/modules/cjs/loader:1243
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\fauxpark\Desktop\bcrypt-test\node_modules\bcrypt\lib\binding\napi-v3\bcrypt_lib.node
    at Module._extensions..node (node:internal/modules/cjs/loader:1243:18)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\Users\fauxpark\Desktop\bcrypt-test\node_modules\bcrypt\bcrypt.js:6:16)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v18.12.1

Verification

Windows Version

MINGW64_NT-10.0-19044

MINGW environments affected

  • MINGW64
  • MINGW32
  • UCRT64
  • CLANG64
  • CLANG32
  • CLANGARM64

Are you willing to submit a PR?

If I can figure out the root cause :)

@fauxpark fauxpark added the bug label Jan 15, 2023
@fauxpark
Copy link
Contributor Author

@raedrizqie any thoughts?

@raedrizqie
Copy link
Contributor

this may be a node-gyp error i think..

@raedrizqie
Copy link
Contributor

after patching node-gyp, i need to run:

npm install dlopen --nodedir=$MINGW_PREFIX

in order to proceed compiling of dlopen module using gcc/clang instead of using msvs (default for windows)

npm install dlopen --nodedir=$MINGW_PREFIX --save-dev
npm ERR! code 1
npm ERR! path C:\MSYS64\home\raed\test\node_modules\dlopen
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! make: Entering directory '/home/raed/test/node_modules/dlopen/build'
npm ERR!   CXX(target) Release/obj.target/binding/src/binding.o
npm ERR! make: Leaving directory '/home/raed/test/node_modules/dlopen/build'
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.9 found at "C:/MSYS64/clang64/bin/python3.exe"
npm ERR! gyp info spawn C:/MSYS64/clang64/bin/python3.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'C:\\MSYS64\\clang64\\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   'C:\\MSYS64\\home\\raed\\test\\node_modules\\dlopen\\build\\config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\MSYS64\\clang64\\lib\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\MSYS64\\clang64\\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=C:/MSYS64/clang64',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=C:\\MSYS64\\clang64\\lib\\node_modules\\npm\\node_modules\\node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\\MSYS64\\clang64\\$(Configuration)\\node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=C:\\MSYS64\\home\\raed\\test\\node_modules\\dlopen',
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 info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ../src/binding.cc:4:
npm ERR! ../../nan/nan.h:206:9: error: no template named 'Handle' in namespace 'v8'
npm ERR!   , v8::Handle<v8::String> opt, bool def
npm ERR!     ~~~~^
npm ERR! ../../nan/nan.h:221:9: error: no template named 'Handle' in namespace 'v8'
npm ERR!   , v8::Handle<v8::String> opt
npm ERR!     ~~~~^
npm ERR! ../../nan/nan.h:228:9: error: no template named 'Handle' in namespace 'v8'
npm ERR!   , v8::Handle<v8::String> opt
npm ERR!     ~~~~^
npm ERR! ../../nan/nan.h:333:3: warning: 'always_inline' attribute only applies to functions and statements [-Wignored-attributes]
npm ERR!   NAN_INLINE v8::Local<v8::Signature> NanNew(
npm ERR!   ^
npm ERR! ../../nan/nan.h:164:43: note: expanded from macro 'NAN_INLINE'
npm ERR! # define NAN_INLINE inline __attribute__((always_inline))
npm ERR!                                           ^
npm ERR! ../../nan/nan.h:333:39: error: redefinition of 'NanNew' as different kind of symbol
npm ERR!   NAN_INLINE v8::Local<v8::Signature> NanNew(
npm ERR!                                       ^
npm ERR! ../../nan/nan.h:328:27: note: previous definition is here
npm ERR!   NAN_INLINE v8::Local<T> NanNew(P arg1) {
npm ERR!                           ^
npm ERR! ../../nan/nan.h:334:38: error: expected '(' for function-style cast or type construction
npm ERR!       v8::Handle<v8::FunctionTemplate> receiver
npm ERR!                  ~~~~~~~~~~~~~~~~~~~~^
npm ERR! ../../nan/nan.h:334:11: error: no member named 'Handle' in namespace 'v8'
npm ERR!       v8::Handle<v8::FunctionTemplate> receiver
npm ERR!       ~~~~^
npm ERR! ../../nan/nan.h:334:40: error: use of undeclared identifier 'receiver'
npm ERR!       v8::Handle<v8::FunctionTemplate> receiver
npm ERR!                                        ^
npm ERR! ../../nan/nan.h:335:11: error: expected '(' for function-style cast or type construction
npm ERR!     , int argc
npm ERR!       ~~~ ^
npm ERR! ../../nan/nan.h:336:38: error: expected '(' for function-style cast or type construction
npm ERR!     , v8::Handle<v8::FunctionTemplate> argv[] = 0) {
npm ERR!                  ~~~~~~~~~~~~~~~~~~~~^
npm ERR! ../../nan/nan.h:336:11: error: no member named 'Handle' in namespace 'v8'
npm ERR!     , v8::Handle<v8::FunctionTemplate> argv[] = 0) {
npm ERR!       ~~~~^
npm ERR! ../../nan/nan.h:336:45: error: expected expression
npm ERR!     , v8::Handle<v8::FunctionTemplate> argv[] = 0) {
npm ERR!                                             ^
npm ERR! ../../nan/nan.h:336:40: error: use of undeclared identifier 'argv'
npm ERR!     , v8::Handle<v8::FunctionTemplate> argv[] = 0) {
npm ERR!                                        ^
npm ERR! ../../nan/nan.h:336:51: error: expected ';' at end of declaration
npm ERR!     , v8::Handle<v8::FunctionTemplate> argv[] = 0) {
npm ERR!                                                   ^
npm ERR!                                                   ;
npm ERR! ../../nan/nan.h:336:52: error: expected unqualified-id
npm ERR!     , v8::Handle<v8::FunctionTemplate> argv[] = 0) {
npm ERR!                                                    ^
npm ERR! ../../nan/nan.h:343:11: error: no template named 'Handle' in namespace 'v8'
npm ERR!     , v8::Handle<v8::Value> data = v8::Handle<v8::Value>()
npm ERR!       ~~~~^
npm ERR! ../../nan/nan.h:343:56: error: expected '(' for function-style cast or type construction
npm ERR!     , v8::Handle<v8::Value> data = v8::Handle<v8::Value>()
npm ERR!                                               ~~~~~~~~~^
npm ERR! ../../nan/nan.h:343:40: error: no member named 'Handle' in namespace 'v8'
npm ERR!     , v8::Handle<v8::Value> data = v8::Handle<v8::Value>()
npm ERR!                                    ~~~~^
npm ERR! ../../nan/nan.h:343:58: error: expected expression
npm ERR!     , v8::Handle<v8::Value> data = v8::Handle<v8::Value>()
npm ERR!                                                          ^
npm ERR! ../../nan/nan.h:344:11: error: no template named 'Handle' in namespace 'v8'
npm ERR!     , v8::Handle<v8::Signature> signature = v8::Handle<v8::Signature>()) {
npm ERR!       ~~~~^
npm ERR! fatal error: too many errors emitted, stopping now [-ferror-limit=]
npm ERR! 1 warning and 20 errors generated.
npm ERR! make: *** [binding.target.mk:96: Release/obj.target/binding/src/binding.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (C:\MSYS64\clang64\lib\node_modules\npm\node_modules\node-gyp\lib\build.js:202:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System MINGW32_NT-6.3 6.3.9600
npm ERR! gyp ERR! command "C:\\MSYS64\\clang64\\bin\\node.exe" "C:\\MSYS64\\clang64\\lib\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\MSYS64\home\raed\test\node_modules\dlopen
npm ERR! gyp ERR! node -v v18.12.1
npm ERR! gyp ERR! node-gyp -v v9.1.0
npm ERR! gyp ERR! not ok

maybe it still searching for installed v8, despite node is using v8 internally?

@raedrizqie
Copy link
Contributor

@fauxpark found a solution here: https://stackoverflow.com/questions/71027495/i-received-this-code-error-each-time-i-tried-to-deploy-may-app-on-herokucode

You can use bcryptjs instead..

const bcrypt = require('bcryptjs')

then..

npm uninstall bcrypt
npm install bcryptjs

@fauxpark
Copy link
Contributor Author

Yes, I did find bcryptjs which I'm sure works fine for a pure JS implementation, but it'd be preferable to have node-gyp functioning properly in MSYS2, for any other packages that need it.

@raedrizqie
Copy link
Contributor

here is the errors i got when trying to build dlopen (or any C/C++ native module):

npm install --nodedir=$MINGW_PREFIX --verbose
npm verb cli C:\MSYS64\clang64\bin\node.exe C:\MSYS64\clang64\lib\node_modules\npm\bin\npm-cli.js
npm info using [email protected]
npm info using [email protected]
npm timing npm:load:whichnode Completed in 1ms
npm timing config:load:defaults Completed in 4ms
npm timing config:load:file:C:\MSYS64\clang64\lib\node_modules\npm\npmrc Completed in 2ms
npm timing config:load:builtin Completed in 2ms
npm timing config:load:cli Completed in 4ms
npm timing config:load:env Completed in 1ms
npm timing config:load:file:C:\MSYS64\home\raed\zd\.npmrc Completed in 0ms
npm timing config:load:project Completed in 3ms
npm timing config:load:file:C:\MSYS64\home\raed\.npmrc Completed in 0ms
npm timing config:load:user Completed in 1ms
npm timing config:load:file:C:\MSYS64\clang64\etc\npmrc Completed in 0ms
npm timing config:load:global Completed in 0ms
npm timing config:load:validate Completed in 0ms
npm timing config:load:credentials Completed in 1ms
npm timing config:load:setEnvs Completed in 2ms
npm timing config:load Completed in 20ms
npm timing npm:load:configload Completed in 20ms
npm timing npm:load:mkdirpcache Completed in 2ms
npm timing npm:load:mkdirplogs Completed in 1ms
npm verb title npm install
npm verb argv "install" "--nodedir" "C:/MSYS64/clang64" "--loglevel" "verbose"
npm timing npm:load:setTitle Completed in 2ms
npm timing config:load:flatten Completed in 6ms
npm timing npm:load:display Completed in 12ms
npm verb logfile logs-max:10 dir:C:\Users\raed\AppData\Local\npm-cache\_logs
npm verb logfile C:\Users\raed\AppData\Local\npm-cache\_logs\2023-01-28T00_07_35_872Z-debug-0.log
npm timing npm:load:logFile Completed in 10ms
npm timing npm:load:timers Completed in 0ms
npm timing npm:load:configScope Completed in 0ms
npm timing npm:load Completed in 49ms
npm timing arborist:ctor Completed in 2ms
npm timing idealTree:init Completed in 35ms
npm timing idealTree:userRequests Completed in 0ms
npm timing idealTree:#root Completed in 0ms
npm timing idealTree:buildDeps Completed in 2ms
npm timing idealTree:fixDepFlags Completed in 1ms
npm timing idealTree Completed in 40ms
npm timing arborist:ctor Completed in 1ms
npm timing reify:loadTrees Completed in 51ms
npm timing reify:diffTrees Completed in 3ms
npm timing reify:retireShallow Completed in 2ms
npm timing reify:createSparse Completed in 0ms
npm timing reify:loadBundles Completed in 0ms
npm timing reify:unpack Completed in 6ms
npm timing reify:unretire Completed in 1ms
npm timing build:queue Completed in 0ms
npm timing build:deps Completed in 1ms
npm timing build Completed in 2ms
npm timing reify:build Completed in 2ms
npm timing reify:trash Completed in 0ms
npm timing reify:save Completed in 11ms
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/advisories/bulk 459ms
npm timing auditReport:getReport Completed in 468ms
npm timing metavuln:cache:get:security-advisory:debug:FyNhEjkaBgh6TBLAJbmqbBYH/G66bPnTqyzF9ABGe88Ye4m1loGRvJl7nIKq7KHPYtDEfbSFcidAJWwemVV/NA== Completed in 46ms
npm timing metavuln:cache:get:security-advisory:debug:gUrdU2CzpVFZ/QZZU+V/N8vQM3go7S4ygXfGS5yqdd0KMLecuidzauIP02g6E3VfE8ssEDtvQTCa40RzcGPgbQ== Completed in 40ms
npm http fetch GET 200 https://registry.npmjs.org/debug 80ms (cache hit)
npm timing metavuln:packument:debug Completed in 88ms
npm timing metavuln:load:security-advisory:debug:1088602 Completed in 3ms
npm timing metavuln:calculate:security-advisory:debug:1088602 Completed in 95ms
npm timing metavuln:load:security-advisory:debug:1087757 Completed in 3ms
npm timing metavuln:calculate:security-advisory:debug:1087757 Completed in 90ms
npm timing auditReport:init Completed in 126ms
npm timing reify:audit Completed in 601ms
npm timing reify Completed in 674ms

> [email protected] install
> node-gyp rebuild

gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   'C:\\MSYS64\\clang64\\bin\\node.exe',
gyp verb cli   'C:\\MSYS64\\clang64\\lib\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'rebuild'
gyp verb cli ]
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - executable path is "C:/MSYS64/clang64/bin/python3.exe"
gyp verb find Python - executing "C:/MSYS64/clang64/bin/python3.exe" to get version
gyp verb find Python - version is "3.10.9"
gyp info find Python using Python version 3.10.9 found at "C:/MSYS64/clang64/bin/python3.exe"
gyp verb get node dir compiling against specified --nodedir dev files: C:/MSYS64/clang64
gyp verb build dir attempting to create "build" dir: C:\MSYS64\home\raed\zd\build
gyp verb build dir "build" dir needed to be created? Yes
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: C:\MSYS64\home\raed\zd\build\config.gypi
gyp verb config.gypi checking for gypi file: C:\MSYS64\home\raed\zd\config.gypi
gyp verb common.gypi checking for gypi file: C:\MSYS64\home\raed\zd\common.gypi
gyp verb gyp gyp format was not specified; forcing "make"
gyp info spawn C:/MSYS64/clang64/bin/python3.exe
gyp info spawn args [
gyp info spawn args   'C:\\MSYS64\\clang64\\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   'C:\\MSYS64\\home\\raed\\zd\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\MSYS64\\clang64\\lib\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\MSYS64\\clang64\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:/MSYS64/clang64',
gyp info spawn args   '-Dnode_gyp_dir=C:\\MSYS64\\clang64\\lib\\node_modules\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\MSYS64\\clang64\\lib\\libnode.dll.a',
gyp info spawn args   '-Dmodule_root_dir=C:\\MSYS64\\home\\raed\\zd',
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 verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir C:/MSYS64/clang64
gyp verb `which` succeeded for `make` C:\MSYS64\usr\bin\make.EXE
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/raed/zd/build'
  c++ -o Release/obj.target/binding/src/binding.o ../src/binding.cc '-DNODE_GYP_MODULE_NAME=binding' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-DWIN32' '-D_CRT_NONSTDC_NO_DEPRECATE' '-D_HAS_EXCEPTIONS=0' '-DBUILDING_NODE_EXTENSION' -IC:/MSYS64/clang64/include/node -IC:/MSYS64/clang64/include/openssl -IC:/MSYS64/clang64/include/uv -IC:/MSYS64/clang64/include -I../node_modules/nan -IC:/MSYS64/clang64/deps/uv/include  -O3 -std=gnu++17 -MMD -MF ./Release/.deps/Release/obj.target/binding/src/binding.o.d.raw   -c
In file included from ../src/binding.cc:2:
In file included from C:/MSYS64/clang64/include/node/node.h:80:
In file included from C:/MSYS64/clang64/include/c++/v1/ostream:169:
In file included from C:/MSYS64/clang64/include/c++/v1/ios:221:
In file included from C:/MSYS64/clang64/include/c++/v1/__locale:19:
In file included from C:/MSYS64/clang64/include/c++/v1/mutex:191:
In file included from C:/MSYS64/clang64/include/c++/v1/__mutex_base:20:
In file included from C:/MSYS64/clang64/include/c++/v1/system_error:147:
C:/MSYS64/clang64/include/c++/v1/__errc:118:43: error: use of undeclared identifier 'EAFNOSUPPORT'; did you mean 'UV_EAFNOSUPPORT'?
    address_family_not_supported        = EAFNOSUPPORT,
                                          ^
C:/MSYS64/clang64/include/uv.h:188:16: note: 'UV_EAFNOSUPPORT' declared here
  UV_ERRNO_MAP(XX)
               ^
C:/MSYS64/clang64/include/c++/v1/__errc:119:43: error: use of undeclared identifier 'EADDRINUSE'; did you mean 'UV_EADDRINUSE'?
    address_in_use                      = EADDRINUSE,
                                          ^
C:/MSYS64/clang64/include/uv.h:188:16: note: 'UV_EADDRINUSE' declared here
  UV_ERRNO_MAP(XX)
               ^
C:/MSYS64/clang64/include/c++/v1/__errc:120:43: error: use of undeclared identifier 'EADDRNOTAVAIL'; did you mean 'UV_EADDRNOTAVAIL'?
    address_not_available               = EADDRNOTAVAIL,
                                          ^
C:/MSYS64/clang64/include/uv.h:188:16: note: 'UV_EADDRNOTAVAIL' declared here
  UV_ERRNO_MAP(XX)
               ^

... and many more like those

Maybe someone can figure out the solution to these error..

@fauxpark
Copy link
Contributor Author

Seems like errno.h isn't getting picked up? Which would make sense, maybe some _WIN32 define or something else is confusing it.

Does the same thing happen in MINGW64, or is the error output different? From what I can tell errno.h should be visible there.

@raedrizqie
Copy link
Contributor

on mingw64 and ucrt64, it fails more or less the same:

npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from C:/MSYS64/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/xmmintrin.h:34,
npm ERR!                  from C:/MSYS64/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/immintrin.h:31,
npm ERR!                  from C:/MSYS64/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/x86intrin.h:32,
npm ERR!                  from C:/MSYS64/mingw64/include/winnt.h:1658,
npm ERR!                  from C:/MSYS64/mingw64/include/minwindef.h:163,
npm ERR!                  from C:/MSYS64/mingw64/include/windef.h:9,
npm ERR!                  from C:/MSYS64/mingw64/include/windows.h:69,
npm ERR!                  from C:/MSYS64/mingw64/include/winsock2.h:23,
npm ERR!                  from C:/MSYS64/mingw64/include/uv/win.h:33,
npm ERR!                  from C:/MSYS64/mingw64/include/uv.h:66,
npm ERR!                  from ../src/binding.cc:1:
npm ERR! C:/MSYS64/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mm_malloc.h: In function 'void* _mm_malloc(size_t, size_t)':
npm ERR! C:/MSYS64/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mm_malloc.h:42:15: error: 'EINVAL' was not declared in this scope
npm ERR!    42 |       errno = EINVAL;
npm ERR!       |               ^~~~~~
npm ERR! In file included from C:/MSYS64/mingw64/include/c++/12.2.0/bits/basic_string.h:3960,
npm ERR!                  from C:/MSYS64/mingw64/include/c++/12.2.0/string:53,
npm ERR!                  from C:/MSYS64/mingw64/include/node/v8-callbacks.h:10,
npm ERR!                  from C:/MSYS64/mingw64/include/node/v8-initialization.h:11,
npm ERR!                  from C:/MSYS64/mingw64/include/node/v8.h:34,
npm ERR!                  from C:/MSYS64/mingw64/include/node/node.h:73,
npm ERR!                  from ../src/binding.cc:2:
npm ERR! C:/MSYS64/mingw64/include/c++/12.2.0/ext/string_conversions.h: In function '_Ret __gnu_cxx::__stoa(_TRet (*)(const _CharT*, _CharT**, _Base ...), const char*, const _CharT*, std::size_t*, _Base ...)':
npm ERR! C:/MSYS64/mingw64/include/c++/12.2.0/ext/string_conversions.h:84:25: error: 'ERANGE' was not declared in this scope; did you mean 'WCRANGE'?
npm ERR!    84 |       else if (errno == ERANGE
npm ERR!       |                         ^~~~~~
npm ERR!       |                         WCRANGE
npm ERR! In file included from C:/MSYS64/mingw64/include/c++/12.2.0/system_error:39,
npm ERR!                  from C:/MSYS64/mingw64/include/c++/12.2.0/bits/ios_base.h:46,
npm ERR!                  from C:/MSYS64/mingw64/include/c++/12.2.0/ios:42,
npm ERR!                  from C:/MSYS64/mingw64/include/c++/12.2.0/ostream:38,
npm ERR!                  from C:/MSYS64/mingw64/include/node/node.h:80:
npm ERR! C:/MSYS64/mingw64/include/c++/12.2.0/x86_64-w64-mingw32/bits/error_constants.h: At global scope:
npm ERR! C:/MSYS64/mingw64/include/c++/12.2.0/x86_64-w64-mingw32/bits/error_constants.h:44:49: error: 'EAFNOSUPPORT' was not declared in this scope; did you mean 'UV_EAFNOSUPPORT'?
npm ERR!    44 |       address_family_not_supported =            EAFNOSUPPORT,
npm ERR!       |                                                 ^~~~~~~~~~~~
npm ERR!       |                                                 UV_EAFNOSUPPORT

@raedrizqie
Copy link
Contributor

@fauxpark Please download from the artifacts here: #15372

install bcrypt module:

npm i bcrypt --verbose

bcrypt will download the prebuilt module and use it instead of rebuilding it locally.. it's not compatible with mingw, so we need to rebuild the module;

cd node_modules/bcrypt
../.bin/node-pre-gyp clean
../.bin/node-pre-gyp rebuild --verbose

finally test the module:

cd ../..
node test.js
$2b$10$bvou4CdW4dby2akntuZIF.AOaJObwPngC3xWEEibBwdYVA3aerola

@fauxpark
Copy link
Contributor Author

fauxpark commented Feb 1, 2023

Tested and working: CLANG64, MINGW64, UCRT64

CLANG32 and MINGW32 fail to rebuild:

make: Entering directory '/c/Users/fauxpark/Desktop/node-test/node_modules/bcrypt/build'
  CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
  AR(target) Release/obj.target/../node-addon-api/nothing.a
  COPY Release/nothing.a
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
In file included from ../src/blowfish.cc:42:
../src/node_blf.h:62:19: error: typedef redefinition with different types
      ('SSIZE_T' (aka 'long') vs 'int')
  typedef SSIZE_T ssize_t;
                  ^
C:/msys64/clang32/include/corecrt.h:47:13: note: previous definition is here
typedef int ssize_t;
            ^
make: Entering directory '/c/Users/fauxpark/Desktop/node-test/node_modules/bcrypt/build'
  CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
  AR(target) Release/obj.target/../node-addon-api/nothing.a
  COPY Release/nothing.a
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
In file included from ../src/blowfish.cc:42:
../src/node_blf.h:62:19: error: conflicting declaration 'typedef SSIZE_T ssize_'
   62 |   typedef SSIZE_T ssize_t;
      |                   ^~~~~~~
In file included from C:/msys64/mingw32/include/crtdefs.h:10,
                 from C:/msys64/mingw32/include/sys/types.h:13,
                 from ../src/node_blf.h:37:
C:/msys64/mingw32/include/corecrt.h:47:13: note: previous declaration as 'typedef int ssize_t'
   47 | typedef int ssize_t;
      |             ^~~~~~~

Doesn't look like a node-gyp issue, and I'm not sure how much we care about 32-bit these days.

Also, is there a way to have this automated on install?

@raedrizqie
Copy link
Contributor

Doesn't look like a node-gyp issue, and I'm not sure how much we care about 32-bit these days.

If we remove typedef SSIZE_T ssize_t; form node_blf.h, it will compile on 32bit

Also, is there a way to have this automated on install?

I dont know how to automate a rebuild.. bcrypt shouldn't provide prebuilt module anyway.. unless they also support mingw built module

@fauxpark
Copy link
Contributor Author

fauxpark commented Feb 1, 2023

Perhaps I should have said "fall back to building from source" instead. Bcrypt is a sufficiently popular package that I think being able to install it without the need for a compilation step on the major platforms is fair and warranted. MSYS2 is not one of those.

From looking at the bcrypt package.json, this automation is already done by node-pre-gyp. The problem is that it sees we're running on Windows (since process.platform is win32) and pulls down the prebuilt Windows module.

If it's possible to detect MINGW in node (process.env contains MSYSTEM as a crude test?) maybe we can ask node-pre-gyp to skip this step.

@raedrizqie
Copy link
Contributor

Perhaps I should have said "fall back to building from source" instead. Bcrypt is a sufficiently popular package that I think being able to install it without the need for a compilation step on the major platforms is fair and warranted. MSYS2 is not one of those.

I agree..

If it's possible to detect MINGW in node (process.env contains MSYSTEM as a crude test?) maybe we can ask node-pre-gyp to skip this step.

The easiest way to rebuild the module while installing it is:

npm i bcrypt --build-from-source

We don't have to further patch node-gyp this way..

@fauxpark
Copy link
Contributor Author

fauxpark commented Feb 1, 2023

The patching won't be in node-gyp, that seems to be fine now thanks to your work. I'm talking about node-pre-gyp: https://nodejs.github.io/node-addon-examples/build-tools/node-pre-gyp/#the-code-classlanguage-textscriptscode-properties

@raedrizqie
Copy link
Contributor

yeah, i understand.. but by patching node-pre-gyp, we need to somehow provide a node-pre-gyp package, no?

@fauxpark
Copy link
Contributor Author

fauxpark commented Feb 1, 2023

I was more thinking along the lines of opening an issue over there to see what they'd prefer to do, if anything.

@raedrizqie
Copy link
Contributor

ah.. that's better I think..

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

Successfully merging a pull request may close this issue.

2 participants