Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module @google-cloud/firestore on AppEngine using node.js standard environment

I have deployed a cron on AppEngine using node.js standard environment in order to update regularly my Firestore database.

Following this doc, linking to this list of available npm modules, I should be able to use @google-cloud/firestore, but after:

npm i --save @google-cloud/firestore

I get the following error:

Error: Cannot find module '@google-cloud/firestore'

At the line:

var firestore = require('@google-cloud/firestore');

My package.json is the same as the Hello World sample:

{
  "name": "appengine-hello-world",
  "description": "Simple Hello World Node.js sample for Google App Engine Standard Environment.",
  "version": "0.0.1",
  "private": true,
  "license": "Apache-2.0",
  "author": "Google Inc.",
  "repository": {
    "type": "git",
    "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
  },
  "engines": {
    "node": "8.x.x"
  },
  "scripts": {
    "deploy": "gcloud app deploy",
    "start": "node app.js",
    "lint": "repo-tools lint",
    "pretest": "npm run lint",
    "system-test": "repo-tools test app",
    "test": "npm run system-test",
    "e2e-test": "repo-tools test deploy"
  },
  "dependencies": {
    "@google-cloud/firestore": "^0.14.1",
    "express": "^4.16.3"
  },
  "devDependencies": {
    "@google-cloud/nodejs-repo-tools": "^2.3.0",
    "semistandard": "^12.0.1"
  },
  "cloud-repo-tools": {
    "test": {
      "app": {
        "msg": "Hello, world!"
      }
    },
    "requiresKeyFile": true,
    "requiresProjectId": true
  }
}

And finally I deploy with:

gcloud app deploy --version=v8 --promote

How am I supposed to use firestore in my cron ?

like image 318
Loheek Avatar asked Jul 10 '18 14:07

Loheek


1 Answers

There seems to be an issue with installing @grpc. If your @grpc was corrupted by a previous attempts to install it, it will likely keep failing if you just keep trying to install. Doing npm install @google-cloud/firestore will also try to install grpc, so the whole thing won't successfully complete if grpc is corrupted.

Try deleting your entire nodes_modules folder and install your packages from scratch.

As to why the grpc gets corrupted in the first place, I'm not too sure. Any clean install from my Windows Shell Command (cmd.exe) gave me the same problem over and over.

However, I was able to successfully install everything on an Ubuntu virtual machine using Ubuntu's linux terminal. Later I realized the same thing was possible even on a Windows OS using Windows' Linux Subsystem instead of Shell Command (here is a video that shows how to setup an Ubuntu terminal for Windows). So the Shell Command seems to be the issue. For some reason that I haven't looked into yet, it's not working well with some @google-cloud/* packages.

That being said, it might also be possible to correctly install those packages on Windows using something like Cmder or anything else than the Shell Command (I can't confirm, I haven't tried).

like image 173
ribbit Avatar answered Nov 19 '22 00:11

ribbit