mapbox / node-pre-gyp

Node.js tool for easy binary deployment of C++ addons
BSD 3-Clause "New" or "Revised" License
1.11k stars 261 forks source link

node v4 error when using napi_versions/napi_build_versions #396

Open springmeyer opened 6 years ago

springmeyer commented 6 years ago

I found that if you add:

    "package_name": "{module_name}-v{version}-{platform}-{arch}-napi-v{napi_build_version}.tar.gz",
    "napi_versions": [
        1,
        2
    ]

To the package.json binary property of a node-pre-gyp enabled module it will lead to this error with node v4:

./node_modules/.bin/node-pre-gyp rebuild --loglevel=error
/Users/danespringmeyer/projects/node-sqlite3/node_modules/node-pre-gyp/lib/util/napi.js:105
            if (!napi_build_versions.includes(napi_version)) napi_build_versions.push(napi_version);
                                     ^

TypeError: napi_build_versions.includes is not a function

This looks to be because Array.includes is not supported with node v4, so we'll either need to use a polyfill or use Array.indexOf instead.

@jschlight two questions for you:

jschlight commented 6 years ago

@springmeyer It is doubtful that N_API will ever be back ported to Node 4. I can address this issue with a meaningful error message in the PR I'm preparing to address some remaining issues I've listed on this issue https://github.com/mapbox/node-pre-gyp/pull/345#issuecomment-379067786

springmeyer commented 6 years ago

I can address this issue with a meaningful error message in the PR I'm preparing to address some remaining issues I've listed on this issue #345 (comment)

👍

jschlight commented 6 years ago

This should be addressed by the work at https://github.com/mapbox/node-pre-gyp/issues/402.