Flavio Del Grosso
Flavio Del Grosso

Reputation: 600

Node.js msnodesqlv8 module not installing in macOS ARM64

I'm working on macOS 11.3.1 ARM64 and I'm trying to install with npm the msnodesqlv8 in my node.js project. I've my homebrew installed in /opt/homebrew/bin/brew, and I've installed with brew the ODBC driver for SQLServer with these commands:

brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools

I've also unixodbc installed.

It seems it's not pointing to the lib in my /opt/homebrew/lib (Library not loaded: /usr/local/opt/msodbcsql17/lib/libmsodbcsql.17.dylib) There's also a problem related with the sqltypes.h file. I did many researches but none solved my problem.

This is the output:

prebuild-install WARN install dlopen(/Users/fdg/project/node_modules/msnodesqlv8/build/Release/sqlserverv8.node, 1): Library not loaded: /usr/local/opt/msodbcsql17/lib/libmsodbcsql.17.dylib
prebuild-install WARN install   Referenced from: /Users/fdg/project/node_modules/msnodesqlv8/build/Release/sqlserverv8.node
prebuild-install WARN install   Reason: image not found
  CXX(target) Release/obj.target/sqlserverv8/src/ConnectionHandles.o
In file included from ../src/ConnectionHandles.cpp:1:
In file included from ../src/ConnectionHandles.h:22:
../src/stdafx.h:37:14: fatal error: 'sqltypes.h' file not found
    #include <sqltypes.h>
             ^~~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/sqlserverv8/src/ConnectionHandles.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Darwin 20.4.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/fdg/project/node_modules/msnodesqlv8
gyp ERR! node -v v14.16.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

These lines are in my .bash_profile:

export PATH=/opt/homebrew/bin:$PATH
export DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH

EDIT: In addition I tried to create symlinks to the homebrew lib. When running the sqlcmd command it says:

dyld: Library not loaded: /usr/local/lib/libodbc.2.dylib
  Referenced from: /opt/homebrew/bin/sqlcmd
  Reason: no suitable image found.  Did find:
    /opt/homebrew/lib/libodbc.2.dylib: mach-o, **but wrong architecture**
    /opt/homebrew/Cellar/unixodbc/2.3.9_1/lib/libodbc.2.dylib: mach-o, but wrong architecture

It seems it's not supported for M1 architecture yet (?). Is there any workaround?

If any extra informations needed to help me figuring out how to solve the problem, please tell me.

Thanks in advance

Upvotes: 3

Views: 3208

Answers (2)

VenatioDecorus
VenatioDecorus

Reputation: 11

Microsoft has added support for Apple's M1 chip. I still got this issue though. I was able to resolve by building msnodesqlv8 locally and updating the binding.gyp file. Find the OS=="mac" section and change it to this:

        ['OS=="mac"', {
            'link_settings': {
             'libraries': ['/opt/homebrew/lib/libodbc.a'],
            },
            'defines': [
              'LINUX_BUILD',
              'UNICODE'
            ], 
            'cflags_cc': [
              '-std=c++1y'
            ],
            'include_dirs': [
              '/usr/local/include/',
              '/usr/local/opt/msodbcsql17/include/',
              '/usr/local/opt/msodbcsql17/include/msodbcsql17/',
              '/opt/homebrew/include',
              '/opt/homebrew/include/msodbcsql17'
            ],
        }]

I was then able to build and then in my project that used this module, I just updated the package.json to point to this local version.

Homebrew moved their Apple silicon packages to /opt/homebrew, so we're updating the linker settings to point to the right library (/opt/homebrew/lib/libodbc.a) and then adding the Homebrew include folders (/opt/homebrew/include and /opt/homebrew/include/msodbcsql17). And make sure msodbcsql17 is >= 17.8.1 as this is the earliest version that supports Apple's ARM platform.

Upvotes: 1

Flavio Del Grosso
Flavio Del Grosso

Reputation: 600

I solved creating a second environment of brew under /usr/local using my terminal under Rosetta for x86_64 architecture. I reinstalled the mssql-tools and msodbcsql17 packages and now reinstalling the msnodesqlv8 module with npm it successfully succeeded.

We'll wait until Microsoft will support ODBC driver for ARM64..

Upvotes: 0

Related Questions