Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joonhocho opened this issue Jun 2, 2019 · 27 comments
Closed
Assignees
Labels
package issue priority Important issue or pull request to fast-track

Comments

@joonhocho
Copy link

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.

@joonhocho joonhocho changed the title grpc-node error: Path must be a string. Received 2726 firebase / firestore / grpc-node error: Path must be a string. Received 2726 Jun 2, 2019
@leerob
Copy link
Member

leerob commented Jun 2, 2019

I am also having this issue.

@netspencer
Copy link

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

@agrohs
Copy link

agrohs commented Jun 3, 2019

We are having the same issue, adding our stack trace in here:

Unhandled rejection: TypeError: Path must be a string. Received 6690
    at assertPath (path.js:28:11)
    at Object.dirname (path.js:1349:5)
    at Object.5193 (/var/task/src/index.js:137965:36)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.7063 (/var/task/src/index.js:207136:25)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.7863 (/var/task/src/index.js:244302:16)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.1807 (/var/task/src/index.js:44865:13)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.1007 (/var/task/src/index.js:26851:25)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Function.get (/var/task/src/index.js:89802:18)
    at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (/var/task/src/index.js:88992:47)
    at ClientPool.acquire (/var/task/src/index.js:183797:35)
    at ClientPool.run (/var/task/src/index.js:183850:29)
    at Firestore.request (/var/task/src/index.js:89610:33)
    at WriteBatch.commit_ (/var/task/src/index.js:278555:14)

This is being triggered only when deployed via now using the following code (snippets pulled out for relevance):

const admin = require('firebase-admin')
cons _firebaseConfig = {
  "type": "service_account",
  "project_id": "REDACTED-FOR-SECURITY",
  "private_key_id": "REDACTED-FOR-SECURITY",
  "private_key": "-----BEGIN PRIVATE KEY-----\nREDACTED-FOR-SECURITY\n-----END PRIVATE KEY-----\n",
  "client_email": "firebase-adminsdk-3gpvn@REDACTED-FOR-SECURITY.iam.gserviceaccount.com",
  "client_id": "REDACTED-FOR-SECURITY",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-3gpvn%40REDACTED-FOR-SECURITY.iam.gserviceaccount.com"
}
...
if (!admin.apps.length) {
  const admin = require('firebase-admin')
  admin.initializeApp({
    credential: admin.credential.cert(_firebaseConfig),
    databaseURL: `https://${_firebaseConfig.project_id}.firebaseio.com`
  });
}
const firestore = admin.firestore()
...
async (req, res) => {
      return firestore
        .collection('someCollection')
        .doc('someDoc')
        .set({ data: 'someData' })
        .then(() => send(res, 200))
    })
...

@styfle styfle added package issue priority Important issue or pull request to fast-track labels Jun 3, 2019
@styfle
Copy link
Member

styfle commented Jun 3, 2019

Related to #392 and possibly #398

@guybedford
Copy link
Contributor

guybedford commented Jun 3, 2019

Thanks for posting @joonhocho. I believe this issue is very likely to be fixed in the ncc 0.19 beta, which hasn't yet been released out into @now/node.

If you're able to provide a sample replication for the issue that I can test against the ncc beta we can confirm that for definite, otherwise that release should be rolling out within the next week.

@FredKSchott
Copy link

@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');

@agrohs
Copy link

agrohs commented Jun 5, 2019

Just checking in to see if any insight/update on here? This is preventing some of our functions from running properly on Now since the Firebase 6 updates?

@styfle
Copy link
Member

styfle commented Jun 6, 2019

@FredKSchott Thanks, I was able to get this code to fail in @zeit/[email protected].

ncc: Version 0.19.0-beta.1
ncc: Compiling file index.js
(node:14265) UnhandledPromiseRejectionWarning: TypeError: replacement content must be a string
    at MagicString.overwrite (evalmachine.<anonymous>:1:531199)
    at e.exports (evalmachine.<anonymous>:1:177864)
    at Object.e.exports (evalmachine.<anonymous>:1:166144)
    at LOADER_EXECUTION (evalmachine.<anonymous>:1:15237)
    at runSyncOrAsync (evalmachine.<anonymous>:1:15248)
    at iterateNormalLoaders (evalmachine.<anonymous>:1:16844)
    at iterateNormalLoaders (evalmachine.<anonymous>:1:16712)
    at evalmachine.<anonymous>:1:16940
    at runSyncOrAsync (evalmachine.<anonymous>:1:15394)
    at iterateNormalLoaders (evalmachine.<anonymous>:1:16844)

@guybedford
Copy link
Contributor

This is resolved in ncc @0.19.

@leerob
Copy link
Member

leerob commented Jun 14, 2019

Would we still need a release of the @now/node builder to consume this?

@FredKSchott
Copy link

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

@lemol
Copy link

lemol commented Jun 17, 2019

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

@leerob
Copy link
Member

leerob commented Jun 18, 2019

If all that is needed is a version bump in @now/node, I'm willing to help out - just not sure if that's the right path forward.

@lemol
Copy link

lemol commented Jun 18, 2019

@leerob , I tried creating a fork of now-builders and bump ncc version in @now/node to 0.19.1, but still no luck. https://github.com/lemol/now-builders/blob/991e9a4b5261af67fbf6f07e0a976001eca4ed26/packages/now-node/package.json#L14

Even specifying my custom builder { use: "@lemol/now" }, now-cli still using version 0.18.5 of @zeit/ncc.

@ywg-jean
Copy link

@lemol if you were able to make the now-builders tests pass after bumping I'm interested in how you solved it.

@styfle
Copy link
Member

styfle commented Jun 18, 2019

All, you can follow the @now/node PR here: https://github.com/zeit/now-builders/pull/632

@slessans
Copy link

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

@ywg-jean
Copy link

@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

@slessans
Copy link

@ywg-jean thank you! Is there a simple way of using zeit cli locally with ncc to unblock development in the meantime? This is my first zeit project, so I'm new to the system.

@ywg-jean
Copy link

@slessans a simple way not really.
I think the simplest would be to clone the now-builders repository, and package a custom version from the zeit/now-builders#641 PR then specify that version as the builder in your now.json. I have not tried it myself and I don't promise it will work though.

Also note that as it is the PR may not work with typescript code because of the last open regression on #434 (see the last comment for a possible workaround but that's too deep for me at the moment)

@agrohs
Copy link

agrohs commented Jul 5, 2019

How are these tangential issues closed if there is no valid workaround posted and it is still causing the same error!??!

@jeantil
Copy link

jeantil commented Jul 5, 2019

The node and node-server builders with the fixes have been released under @canary they built my project with firebase-admin 8.2.x just fine.

@agrohs
Copy link

agrohs commented Jul 5, 2019

Yes, I follow that @jeantil (and am testing now moving our now.json to point to the @now/node@canary builder) BUT these issues related shouldn't be closed IMHO until the steps to resolve have been posted here and the builder has been released outside of canary. This is a huge breaking issue that has been going on for weeks and really difficult to follow all of the latest w/ referenced issues being closed rather than left open until resolved.

@agrohs
Copy link

agrohs commented Jul 5, 2019

I just updated to point to @now/node@canary and now instead of the error we were seeing before:

Unhandled rejection: TypeError: Path must be a string. Received 6690
    at assertPath (path.js:28:11)
    at Object.dirname (path.js:1349:5)
    at Object.5193 (/var/task/src/index.js:137965:36)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.7063 (/var/task/src/index.js:207136:25)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.7863 (/var/task/src/index.js:244302:16)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.1807 (/var/task/src/index.js:44865:13)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.1007 (/var/task/src/index.js:26851:25)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Function.get (/var/task/src/index.js:89802:18)
    at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (/var/task/src/index.js:88992:47)
    at ClientPool.acquire (/var/task/src/index.js:183797:35)
    at ClientPool.run (/var/task/src/index.js:183850:29)
    at Firestore.request (/var/task/src/index.js:89610:33)
    at WriteBatch.commit_ (/var/task/src/index.js:278555:14)

we are now seeing:

Unhandled rejection: Error: @grpc/grpc-js only works on Node ^8.13.0 || >=10.10.0
    at Object.5112 (/var/task/tmp/77642a69/node_modules/@grpc/grpc-js/build/src/index.js:45:1)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.9582 (/var/task/src/index.js:229603:14)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.959 (/var/task/tmp/77642a69/node_modules/google-gax/build/src/index.js:33:16)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.3105 (/var/task/src/index.js:74105:13)
    at __webpack_require__ (/webpack/bootstrap:19:1)
    at Object.429 (/var/task/tmp/77642a69/node_modules/@google-cloud/firestore/build/src/v1/index.js:15:25)
    at __webpack_require__ (/webpack/bootstrap:19:1)

@styfle
Copy link
Member

styfle commented Jul 5, 2019

@agrohs This error indicates that you must use a new version of Node.

Today, ZEIT Now defaults to Node 8.10.x but you can enable Node 10.x by assigning engines in your package.json as documented here: https://zeit.co/docs/v2/deployments/official-builders/node-js-now-node#node.js-version

Also see the Node 10 blog post from last week.

@agrohs
Copy link

agrohs commented Jul 6, 2019

Thanks @styfle, just saw that Node 10 post last night and added the engines into our package.json and all finally working. Looking forward to the ncc update moving from canary to released but at least working on canary for now!

@rishabhzvky
Copy link

rishabhzvky commented May 25, 2020

Unhandled error TypeError: Path must be a string. Received { nested: { google: { nested: [Object] } } } at assertPath (path.js:28:11) at Object.basename (path.js:1377:5) at GrpcClient.loadProto (/srv/node_modules/google-gax/build/src/grpc.js:117:29) at new FirestoreClient (/srv/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:118:38) at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (/srv/node_modules/@google-cloud/firestore/build/src/index.js:329:26) at ClientPool.acquire (/srv/node_modules/@google-cloud/firestore/build/src/pool.js:87:35) at ClientPool.run (/srv/node_modules/@google-cloud/firestore/build/src/pool.js:164:29) at _retry (/srv/node_modules/@google-cloud/firestore/build/src/index.js:957:30) at Firestore._retry (/srv/node_modules/@google-cloud/firestore/build/src/index.js:822:38)

I am getting this issue now. I am using node 8 on firebase cloud functions.
Anyone to help out here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package issue priority Important issue or pull request to fast-track
Projects
None yet
Development

No branches or pull requests