I am getting a build error when trying to install global packages that depend on sqlite3. I am not quite sure how to go about debugging node build errors like this so any help is appreciated. From searching, I can tell that at least the xcode
error is not the problem.
I recently updated OSSierra and Node
OSSierra: 10.13.4
Node: 10.0.0
Yarn: 1.6.0
The command I am running this time. I have experienced the same error doing a global install of other packages, so I don't think the exact npm package is important...
$ yarn global add import-js
The Error
yarn global v1.6.0
(node:17489) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[1/4]
Quick solution
Downgrade from node 10.x to the previous node LTS 8.x: https://github.com/nodejs/Release
This is trivial if you are using NVM, which you should: https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version/1115255#1115255
Correct solution: upgrade the dependencies to use newer nan
You likely have a dependency that depends on an older nan that does not support node 10.x, node-sass is a notable one.
First find the failing package by reading the logs, or use: How to view the dependency tree of a given npm module?
This seems to be the version of nan that removed ForceSet:
https://github.com/nodejs/nan/commit/95cbb976d6fbbba88ba0f86dd188223a8591b4e7
With: How to list all tags that contain a commit? we see that this commit went into: v2.8.0
So, you need to manage your dependencies such that everything uses nan newer than v2.8.0.
And then add an
.nvmrc
to your project to indicate to people what version of Node you tested with, as explained here.What is nan?
nan is a portability helper to maintain the v8 API more stable for native node packages.
v8 is included in the node source code at deps/v8.
So a while back, v8 must have dropped
ForceSet
. nan must have kept it for a longer time for portability. But eventually even nan decided it was time to remove it.Most of the log is just noise of deprecation warnings, but the single error that causes this is:
The problem here is that V8 has removed
ForceSet
method in the V8 version that Node 10 uses, which in turn is what thenan
module uses.nan
has not yet caught up to the breaking changes in V8.The
import-js
package you're trying to install depends on version^3.1.12
ofsqlite3
. Since there are no breaking changes insqlite3
's public API between version 4 and 3, you should be able to override the version ofsqlite3
thatimport-js
depend on. The difference between3.1.13
and4.0.0
can be seen here.To override
import-js
's version ofsqlite3
, you can add a selective version resolution-block to your~/config/yarn/global/package.json
:And afterwards,
yarn global remove import-js
followed byyarn global add import-js
. It does compile on my Sierra as well as my Linux-based OS. I'm not guaranteeing that everything will work flawlessly, but in theory it should as there are no breaking API changes tosqlite3
.