[ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Object
See original GitHub issueEnvironment:
- Operating System version: macOS 10.15.3
- Firebase SDK version: firebase-admin 8.0.0 - 8.9.2
- Firebase Product: Firestore
- Node.js version: 12.16.0
- NPM version: 6.13.4
Describe the problem
I noticed this issue when trying to upgrade my admin-sdk from 7.2.0 to something that does not use the legacy metadata endpoints.
Trying to use the admin sdk to access firestore in a jest test causes this error – TypeError: The “path” argument must be of type string. Received an instance of ObjectTypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string. Received an instance of Object
I do not notice this on my cloud functions deployment or any non jest scripts I’ve tried.
The stack trace is as follows:
TypeError: The "path" argument must be of type string. Received an instance of ObjectTypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Object
11 | describe('testing', () => {
12 | it ('does the thing', async () => {
> 13 | const doc = await adminDb.doc('movers/gea8cKBpFunx5VdE0lRw').get();
| ^
14 | expect(doc.exists).toBe(true);
15 | console.log(doc.data());
16 | });
at GrpcClient.loadProto (node_modules/google-gax/src/grpc.ts:166:23)
at new FirestoreClient (node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:113:32)
at ClientPool.clientFactory (node_modules/@google-cloud/firestore/build/src/index.js:329:26)
at ClientPool.acquire (node_modules/@google-cloud/firestore/build/src/pool.js:87:35)
at ClientPool.run (node_modules/@google-cloud/firestore/build/src/pool.js:164:29)
at node_modules/@google-cloud/firestore/build/src/index.js:957:30
at Firestore._retry (node_modules/@google-cloud/firestore/build/src/index.js:822:38)
at Object.<anonymous> (test.js:13:17)
Relevant Code:
This template replicates the problem for me:
require('jest');
jest.setTimeout(20000);
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert(require("./<keyfile>.json")),
databaseURL: "https://<project>.firebaseio.com",
});
const adminDb = admin.firestore();
describe('testing', () => {
it ('does the thing', async () => {
const doc = await adminDb.doc('<collection>/<id>').get();
expect(doc.exists).toBe(true);
console.log(doc.data());
});
});
My package dependencies are just:
"dependencies": {
"firebase-admin": "^8.9.2",
"jest": "^25.1.0"
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:16
- Comments:19 (7 by maintainers)
Top Results From Across the Web
The "path" argument must be of type string ... - Stack Overflow
I'm working on a project in React and ran into a problem that has me stumped. Whenever I run yarn start I get...
Read more >[Fix] TypeError [ERR_INVALID_ARG_TYPE]: The “path ...
Have you run into the error “TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string. Received undefined”? In this story I'll go...
Read more >npm err! code err_invalid_arg_type npm err! the path ...
Received an instance of Object at new NodeError (node:internal/errors:371:5) TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string.
Read more >The "url" argument must be of type string. Received undefined ...
I got this error while seed the data from nodejs to mongo DB.
Read more >The path argument must be of type string - Reactgo
Received type undefined raised when starting the react app. When we run an npm start or yarn start command in our project, the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Adding a jest.config.js with the following code will solve the issue
Hi @ankittater, thank you so much for that.
My tests run almost perfectly now. There’s a small issue with jest complaining about open handles that didn’t exist, and then hanging for an extra minute or two, but all the test work as intended, and I can tell if a regression happened.
I’d also like to point out for anyone else, the key line for me was this: