[GH-ISSUE #218] Error: Could not load the default credentials #2191

Closed
opened 2026-03-15 17:57:59 +03:00 by kerem · 2 comments
Owner

Originally created by @Fruzenshtein on GitHub (Apr 20, 2020).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/218

I was playing around with the docker fake-gcs-server. Based on nodeJS example from this repo, I copy-pasted the sample code and modified it a little:

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
process.on("unhandledRejection", err => {throw err});

async function testOperation() {
  
  const {Storage} = require("@google-cloud/storage");

  const storage = new Storage({
    apiEndpoint: "127.0.0.1:4443",
    projectId: "test",
  });

  const bucket = storage.bucket('photos');

  bucket.create()
    .then(function(data) {
      const b = data[0];
      console.log(b.name)
    })

  const file = bucket.file('note.txt');
  const contents = 'Happy working prototype!';

  file.save(contents).then(function() {});

}

testOperation().then(console.log);

When I run it, I got:

process.on("unhandledRejection", err => {throw err});
                                         ^

Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
    at GoogleAuth.getApplicationDefaultAsync (/Users/Alex/Desktop/projects/contestio/api/node_modules/google-auth-library/build/src/auth/googleauth.js:160:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async GoogleAuth.getClient (/Users/Alex/Desktop/projects/contestio/api/node_modules/google-auth-library/build/src/auth/googleauth.js:502:17)
    at async GoogleAuth.request (/Users/Alex/Desktop/projects/contestio/api/node_modules/google-auth-library/build/src/auth/googleauth.js:555:24)
    at async Upload.makeRequest (/Users/Alex/Desktop/projects/contestio/api/node_modules/gcs-resumable-upload/build/src/index.js:316:21)
    at async Upload.createURIAsync (/Users/Alex/Desktop/projects/contestio/api/node_modules/gcs-resumable-upload/build/src/index.js:142:22)
Originally created by @Fruzenshtein on GitHub (Apr 20, 2020). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/218 I was playing around with the docker `fake-gcs-server`. Based on nodeJS example from this repo, I copy-pasted the sample code and modified it a little: ``` process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; process.on("unhandledRejection", err => {throw err}); async function testOperation() { const {Storage} = require("@google-cloud/storage"); const storage = new Storage({ apiEndpoint: "127.0.0.1:4443", projectId: "test", }); const bucket = storage.bucket('photos'); bucket.create() .then(function(data) { const b = data[0]; console.log(b.name) }) const file = bucket.file('note.txt'); const contents = 'Happy working prototype!'; file.save(contents).then(function() {}); } testOperation().then(console.log); ``` When I run it, I got: ``` process.on("unhandledRejection", err => {throw err}); ^ Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. at GoogleAuth.getApplicationDefaultAsync (/Users/Alex/Desktop/projects/contestio/api/node_modules/google-auth-library/build/src/auth/googleauth.js:160:19) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async GoogleAuth.getClient (/Users/Alex/Desktop/projects/contestio/api/node_modules/google-auth-library/build/src/auth/googleauth.js:502:17) at async GoogleAuth.request (/Users/Alex/Desktop/projects/contestio/api/node_modules/google-auth-library/build/src/auth/googleauth.js:555:24) at async Upload.makeRequest (/Users/Alex/Desktop/projects/contestio/api/node_modules/gcs-resumable-upload/build/src/index.js:316:21) at async Upload.createURIAsync (/Users/Alex/Desktop/projects/contestio/api/node_modules/gcs-resumable-upload/build/src/index.js:142:22) ```
kerem closed this issue 2026-03-15 17:58:04 +03:00
Author
Owner

@fsouza commented on GitHub (Apr 20, 2020):

Hi @Fruzenshtein, thanks for opening this issue! This is interesting, the bucket creation succeeds but it looks like when you call bucket.file() the SDK doesn't persist the client configuration. You probably need to dig into their docs or source code on how to properly set that.

Closing as this appears to be an issue with the SDK, not the server.

<!-- gh-comment-id:616825004 --> @fsouza commented on GitHub (Apr 20, 2020): Hi @Fruzenshtein, thanks for opening this issue! This is interesting, the bucket creation succeeds but it looks like when you call ``bucket.file()`` the SDK doesn't persist the client configuration. You probably need to dig into their docs or source code on how to properly set that. Closing as this appears to be an issue with the SDK, not the server.
Author
Owner

@fsfarah commented on GitHub (Jul 16, 2020):

Hi, I found out that adding {resumable:false} when creating a writestream works
source: https://github.com/googleapis/nodejs-storage/issues/898

<!-- gh-comment-id:659530585 --> @fsfarah commented on GitHub (Jul 16, 2020): Hi, I found out that adding `{resumable:false}` when creating a writestream works source: https://github.com/googleapis/nodejs-storage/issues/898
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#2191
No description provided.