blog icon indicating copy to clipboard operation
blog copied to clipboard

Getting node-odbc working on Mac M1/arm64 (without Rosetta)

Open worksofliam opened this issue 4 years ago • 2 comments

  1. Install brew:
    • /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
    • Latest at https://brew.sh/
  2. Install unixodbc: brew install unixodbc
  3. Download app package from IBM: https://www.ibm.com/support/pages/ibm-i-access-client-solutions
  4. Since it’s not made for arm64 (m1) yet, we need to change the .pkg file manually.
    1. pkgutil --expand ibm-iaccess-1.1.0.15.pkg ./out
    2. Edit ./out/Distrubution. Change hostArchitectures="x86_64” to hostArchitectures="x86_64,arm64”
    3. pkgutil --flatten ./out ./ibm.pkg
    4. In the future, IBM will fix this so you don't have to change it.
  5. Run the newly created ibm.pkg
    1. You should not see the warning about Rosetta not being installed.
    2. You should not see the warning about unixodbc missing. If you did, you did something wrong.

Actually compiling node-odic:

I had to make two updates to the binding.gyp to make ODBC actually compile from npm i (yarn)

        [ 'OS == "mac"', {
          'include_dirs': [
            '/usr/local/include',
            '/opt/homebrew/include'
          ],
          'libraries' : [
            '-L/usr/local/lib',
            '-L/opt/homebrew/lib',
            '-lodbc'
          ],
          'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS', 'NAPI_EXPERIMENTAL' ]
        }],

Installing and compiling odbc with npm/yarn has to be done in two separate steps.

  1. Remove odbc from your package
  2. npm i or yarn to install the rest of your packages
  3. npm i odbc@x —ignore-scripts or yarn add odbc@x —ignore-scripts to install node-odbc without compiling
  4. Make the change to the binding.gyp file in ./node_modules/odbc to make the build work for the m1.
  5. Run npm run install to build ODBC for your app.

These steps will likely be redundant when node-odbc is updated to work on m1/arm64

worksofliam avatar Sep 06 '21 16:09 worksofliam

You saved my life, thanks!

ilpredo avatar Apr 15 '22 10:04 ilpredo

Looks like support has since been added to node-odbc in version 2.4.6 https://github.com/markdirish/node-odbc/commit/286de6ec624e5da4a79b1d93dee003c1e123cd32

thealexbaron avatar Oct 27 '22 21:10 thealexbaron