Istorn
Istorn

Reputation: 596

Dialogflow: throw new Error(`@grpc/grpc-js only works on Node ${supportedNodeVersions}`)

I'm trying to replicate the Dialogflow Blog's example: https://blog.dialogflow.com/post/create-and-manage-entities-with-api/

The code is the following:

    'use strict';

const admin=require('firebase-admin');


const dialogflow = require('dialogflow');

// Read in credentials from file. To get it, follow instructions here, but
// choose 'API Admin' instead of 'API Client':
// https://dialogflow.com/docs/reference/v2-auth-setup
const credentials = require('./test1drawio.json');

const entitiesClient = new dialogflow.EntityTypesClient({
 credentials: credentials,
});

const projectId = 'projectID';
const agentPath = entitiesClient.projectAgentPath(projectId);

const cityEntityType = {
    displayName: 'city',
    kind: 'KIND_MAP',
    entities: [
      {value: 'New York', synonyms: ['New York', 'NYC']},
      {value: 'Los Angeles', synonyms: ['Los Angeles', 'LA', 'L.A.']},
    ],
   };

   const cityRequest = {
    parent: agentPath,
    entityType: cityEntityType,
   };

   entitiesClient
      .createEntityType(cityRequest)
      .then((responses) => {
        console.log('Created new entity type:', JSON.stringify(responses[0]));

      const streetEntityType = {
        displayName: 'street',
        kind: 'KIND_MAP',
        entities: [
          {value: 'Broadway', synonyms: ['Broadway']},
        ]
      };

       const streetRequest = {
         parent: agentPath,
         entityType: streetEntityType,
       };

       return entitiesClient.createEntityType(streetRequest);
     })

     .then((responses) => {
       console.log('Created new entity type:', JSON.stringify(responses[0]));
     })
     .catch((err) => {
        console.error('Error creating entity type:', err);
      });

If I try to execute it, will be thrown the error mentioned in the answer title.

I've of course checked npm, Node and other packages version, this is the package.json file:

    {
  "name": "tesilaurea",
  "version": "1.0.0",
  "description": "Tesi di Laurea Dialogflow",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Lorenzo Neri",
  "license": "MIT",
  "keywords": [],
  "dependencies": {
    "dialogflow": "^0.10.3",
    "firebase-admin": "^8.3.0",
    "firebase-functions": "3.2.0",
    "grpc": "^1.20.2",
    "node": "12.8.0"
  },
  "engines": {
    "node": "^8.13.0"
  }
}

I rebuilt, downgraded and tried again to execute it, with no success.

Upvotes: 1

Views: 5430

Answers (1)

Nikhil Savaliya
Nikhil Savaliya

Reputation: 2166

Step 1. Check Your NodeJS version, - node -v

Step 2. Upgrade Your Node to LTS or above, To update you can use nvm or this

Step 3. After updating remove your package-lock.json and node_modules folder and again reinstall it.

Upvotes: 4

Related Questions