tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.

Home Page:https://js.tensorflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-pre-gyp info This Node instance does not support builds for N-API version 8

aravindvnair99 opened this issue · comments

I am trying to use TensorFlow with Firebase Cloud Functions. I'm on Node.js v14.16.0 which should be Node-API v7.

And I get this when starting the server:

$ firebase serve
!  D:\folder_name\functions\node_modules\@tensorflow\tfjs-automl\dist\index.js:18
export { ImageClassificationModel, loadImageClassification } from './img_classification';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (D:\folder_name\functions\index.js:14:11)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
!  We were unable to load your functions code. (see above)
$ head -n 14 index.js
const functions = require("firebase-functions"),
        express = require("express"),
        app = express(),
        admin = require("firebase-admin"),
        cookieParser = require("cookie-parser"),
        Busboy = require("busboy"),
        path = require("path"),
        os = require("os"),
        fs = require("fs"),
        vader = require("vader-sentiment"),
        morgan = require("morgan"),
        axios = require("axios"),
        tfnode = require("@tensorflow/tfjs-node"),
        automl = require("@tensorflow/tfjs-automl");
$ node
Welcome to Node.js v14.16.0.
Type ".help" for more information.
> console.log(process.versions.napi)
7
undefined
> .exit
$ cat package.json
"dependencies": {
                "@tensorflow/tfjs-automl": "^1.1.0",
                "@tensorflow/tfjs-converter": "^3.3.0",
                "@tensorflow/tfjs-core": "^3.3.0",
                "@tensorflow/tfjs-node": "^3.6.1",
        },

MCVE available at: https://github.com/aravindvnair99/TFJS-Issue-5017

I've set up a GitHub Actions workflow to reproduce the issue on multiple OS and Node.js versions. Results are available here: https://github.com/aravindvnair99/TFJS-Issue-5017/actions

It's failing in all cases. Workflow configuration: https://github.com/aravindvnair99/TFJS-Issue-5017/blob/main/.github/workflows/node.js.yml

Latest version has support for napi version 8 https://github.com/tensorflow/tfjs/pull/4991/files , please try latest version. Thank you

Latest version has support for napi version 8 https://github.com/tensorflow/tfjs/pull/4991/files , please try latest version. Thank you

@rthadur I'm sorry, I didn't understand. I'm on Node.js 14 which is 7 and not 8.

@aravindvnair99 Thank you for reporting, can you share the full error message?

@aravindvnair99 Thank you for reporting, can you share the full error message?

@pyu10055 It's what I put in my first message itself. Everything else wasn't an error message. Just the usual Firebase loading.

@pyu10055 @rthadur @gbaned I've put together an MCVE with instructions to reproduce: https://github.com/aravindvnair99/TFJS-Issue-5017

Update: I've added 4 different test cases.

I've set up a GitHub Actions workflow to reproduce the issue on multiple OS and Node.js versions. Results are available here: https://github.com/aravindvnair99/TFJS-Issue-5017/actions

It's failing in all cases. Workflow configuration: https://github.com/aravindvnair99/TFJS-Issue-5017/blob/main/.github/workflows/node.js.yml

@aravindvnair99 Looks like the failure is not on the tfjs-node library but the tfjs-autoML, you can use the latest version 1.2.0 of tfjs-autml which have solve the node.js compatibility issue.

@pyu10055 Can confirm updating to @tensorflow/tfjs-automl v1.2.0 has resolved the issue.

Fixed in #5024

Are you satisfied with the resolution of your issue?
Yes
No

I am still getting node-pre-gyp info This Node instance does not support builds for N-API version 8 and using node v14.16.0. Also only trying to use "@tensorflow/tfjs-node": "3.6.1". No automl.
Any ideas?

I am still getting node-pre-gyp info This Node instance does not support builds for N-API version 8 and using node v14.16.0. Also only trying to use "@tensorflow/tfjs-node": "3.6.1". No automl.
Any ideas?

@Fabiansson I too still get it. But I had closed this issue as the other bug I've mentioned had got fixed. That bug prevented me from using the module itself. I guess I'll re-open this issue.

@pyu10055 Could you confirm which Node.js versions are supported? It would be good to have this mentioned in the documentation as well as I found certain files aren't available in the bucket from where it's fetching files to build.

To be clear I did not manage to install the newest tfjs-node on any Node Version. I tested on Node: 10x, 12x, 14x and even 16x. Would have to look up which version exactly. I tried on Windows, Ubuntu and WSL(Ubuntu). Some combinations will not install at all and also manual building does not work reliably. I'm genuinly surprised not more people are having this problem. I really don't know what else I could try. Maybe someone can specify a exact working combination of Node-Version, OS and tfjs-node version so I could try this.

Make sure you have the necessary build tools installed in your system. ( For ubuntu or debian based use sudo apt install build-essential , for windows npm i windows-build-tools).

Now try these versions :
Node 16.x
@tensorflow/tfjs-node 3.7.0

Tested today on Ubuntu 20.04.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

Not stale

@pyu10055 @rthadur Could you confirm which Node.js versions are supported? It would be good to have this mentioned in the documentation as well as certain files are not available in the bucket from where it is fetching files to build.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

Not stale

@aravindvnair99 Not sure if you're still running into this, but I just solved a similar issue in one of my projects. In my case, I was using electron, which bundles its own version of Node (separate from the version I had installed). In my code I ran console.log('Version: ' + process.version); and it spat out v14.6.0, which was Napi 7. Updating electron (and therefore the version of node bundled with it) fixed the issue. Firebase might similarly bundle an old version of node with their CLI.

@aravindvnair99 did you get chance to check above solution ?

Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!