ncc: firebase / firestore / grpc-node error: Path must be a string. Received 2726

I am trying to deploy a function using firebase-admin to zeit using now 2. The error happens when I try to save data to firebase’s firestore.

I get the following error saving to firestore:

TypeError: Path must be a string. Received 2726
    at assertPath (path.js:28:11)
    at Object.dirname (path.js:1349:5)
    at Object.1005 (/private/var/folders/d_/dw16hpwd61v1by98dj1m63mr0000gn/T/zeit-fun-38069aac8e744/src/lambda/event/login/index.ts:16470:36)
    at __webpack_require__ (/webpack/bootstrap:19:1)

Problem is caused by the following part of the compiled code: As you can see below, path.dirname is called with number 2726, not string.

// Load Google's well-known proto files that aren't exposed by Protobuf.js.
{
    // Protobuf.js exposes: any, duration, empty, field_mask, struct, timestamp,
    // and wrappers. compiler/plugin is excluded in Protobuf.js and here.
    var wellKnownProtos = ['api', 'descriptor', 'source_context', 'type'];
    var sourceDir = path.join(path.dirname(/*require.resolve*/(2726)), 'google', 'protobuf');
    for (var _i = 0, wellKnownProtos_1 = wellKnownProtos; _i < wellKnownProtos_1.length; _i++) {
        var proto = wellKnownProtos_1[_i];
        var file = path.join(sourceDir, proto + ".proto");
        var descriptor_1 = Protobuf.loadSync(file).toJSON();
        // @ts-ignore
        Protobuf.common(proto, descriptor_1.nested.google.nested);
    }
}

The original source code for the above snippet is this: https://github.com/grpc/grpc-node/blob/master/packages/proto-loader/src/index.ts#L327

/ Load Google's well-known proto files that aren't exposed by Protobuf.js.
{
  // Protobuf.js exposes: any, duration, empty, field_mask, struct, timestamp,
  // and wrappers. compiler/plugin is excluded in Protobuf.js and here.
  const wellKnownProtos = ['api', 'descriptor', 'source_context', 'type'];
  const sourceDir = path.join(
      path.dirname(require.resolve('protobufjs')), 'google', 'protobuf');

  for (const proto of wellKnownProtos) {
    const file = path.join(sourceDir, `${proto}.proto`);
    const descriptor = Protobuf.loadSync(file).toJSON();

    // @ts-ignore
    Protobuf.common(proto, descriptor.nested.google.nested);
  }
}

I’ve tried both @now/node and @now/node@canary with latest packages.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 27 (9 by maintainers)

Most upvoted comments

Yes, would love some info on when we can expect this to be usable on zeit/now, currently using Google Cloud for the Pika CDN as a workaround for this

Why is this closed? Is there a fix for this anywhere?

Is there any way to make this fix work with now?

I am also having this issue.

@slessans the ncc bug itself is closed and was released in ncc 0.19.x the now-builders didn’t upgrade to 0.19.x because there was a fairly large api change in ncc which was reverted in 0.20.x The upgrade to 0.20.x is in progress in zeit/now-builders#641 but is blocked by regressions for now see #434

@guybedford @google-cloud/firestore is the problematic dependency for me, I can’t get it to work with @now/node. This is working with Google Cloud functions, so I do have a current workaround.

fwiw I can reproduce this in a simple app with the following require calls (its most likely just @google-cloud/firestore on it’s own, but wanted to share the full list just in case):

// now --version = 15.3.0
// Error: Unhandled rejection: TypeError: Path must be a string. Received 560

const url = require("url");
const got = require("got");
const LRU = require("lru-cache");
const getPackageJson = require('package-json');
const marked = require('marked');
const Firestore = require('@google-cloud/firestore');

I am having this issue too! Might be something with the node version not being compatible. Google Cloud’s SDK sometimes is node 10 only