Node sqlite node-gyp build error: no member named

2019-02-23 10:56发布

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]                 

2条回答
Luminary・发光体
2楼-- · 2019-02-23 11:19

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:

commit 95cbb976d6fbbba88ba0f86dd188223a8591b4e7
Author: Benjamin Byholm <bbyholm@abo.fi>
Date:   Wed Nov 1 01:10:24 2017 +0200

    Use DefineOwnProperty instead of 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.

查看更多
淡お忘
3楼-- · 2019-02-23 11:21

Most of the log is just noise of deprecation warnings, but the single error that causes this is:

In file included from ../src/database.cc:4:
In file included from ../src/database.h:10:
In file included from ../../nan/nan.h:192:
../../nan/nan_maybe_43_inl.h:112:15: error: no member named 'ForceSet' in 'v8::Object'
  return obj->ForceSet(isolate->GetCurrentContext(), key, value, attribs);
         ~~~  ^

The problem here is that V8 has removed ForceSet method in the V8 version that Node 10 uses, which in turn is what the nan 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 of sqlite3. Since there are no breaking changes in sqlite3's public API between version 4 and 3, you should be able to override the version of sqlite3 that import-js depend on. The difference between 3.1.13 and 4.0.0 can be seen here.

To override import-js's version of sqlite3, you can add a selective version resolution-block to your ~/config/yarn/global/package.json:

...
"resolutions": {
  "import-js/**/sqlite3": "^4.0.0"
},
...

And afterwards, yarn global remove import-js followed by yarn 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 to sqlite3.

查看更多
登录 后发表回答