"nodejs_compat" breaks when needing crypto.createSign

For Workes & Pages, what is the name of the domain?

https://new-functions.lingdocsdev.workers.dev

What is the error message?

✘ [ERROR] Error: [unenv] crypto.createSign is not implemented yet!

What is the issue or error you’re encountering

The nodejs_compat does not work with crypto.createSign beause the version of unenv has not implemented it yet

What steps have you taken to resolve the issue?

I am trying to use the google sheets api. While this worked just fine with Firebase Functions on Node, it fails to work with Cloudflare Workers while using the "nodejs_compat flag.

As you can see from this error message the problem is that it is relying on unenv for compatability, and this version library has not yet implemented crypto.createSign

✘ [ERROR] Error: [unenv] crypto.createSign is not implemented yet!

      at createNotImplementedError
  (file:///Users/me/my-project/new-functions/node_modules/unenv/runtime/_internal/utils.mjs:22:10)
      at Object.fn [as createSign]
  (file:///Users/me/my-project/new-functions/node_modules/unenv/runtime/_internal/utils.mjs:26:11)
      at Object.sign
  (file:///Users/me/my-project/new-functions/node_modules/jwa/index.js:151:25)
      at Object.jwsSign [as sign]
  (file:///Users/me/my-project/new-functions/node_modules/jws/lib/sign-stream.js:32:24)
      at GoogleToken._GoogleToken_requestToken
  (file:///Users/me/my-project/new-functions/node_modules/gtoken/build/src/index.js:235:27)
      at GoogleToken._GoogleToken_getTokenAsyncInner
  (file:///Users/me/my-project/new-functions/node_modules/gtoken/build/src/index.js:180:97)
      at GoogleToken._GoogleToken_getTokenAsync
  (file:///Users/me/my-project/new-functions/node_modules/gtoken/build/src/index.js:160:173)
      at GoogleToken.getToken
  (file:///Users/me/my-project/new-functions/node_modules/gtoken/build/src/index.js:110:102)
      at JWT.refreshTokenNoCache
  (file:///Users/me/my-project/new-functions/node_modules/google-auth-library/build/src/auth/jwtclient.js:173:36)
      at JWT.refreshToken
  (file:///Users/me/my-project/new-functions/node_modules/google-auth-library/build/src/auth/oauth2client.js:187:24)

What are the steps to reproduce the issue?

Using googleapis v. 144.0.0 and hono v. 4.6.12 on MacOS

import { Hono } from "hono";
import { google } from "googleapis";

const app = new Hono();

app.get("/", async (c) => {
  const auth = new google.auth.GoogleAuth({
    credentials: {
      // @ts-expect-error
      private_key: c.env.SERVICE_ACCOUNT_KEY,
      // @ts-expect-error
      client_email: c.env.SERVICE_ACCOUNT_EMAIL,
    },
    scopes: [
      "https://www.googleapis.com/auth/spreadsheets",
      "https://www.googleapis.com/auth/drive.file",
    ],
  });
  const { spreadsheets } = google.sheets({
    version: "v4",
    auth,
  });
  const { data } = await spreadsheets.values.get({
    // @ts-expect-error
    spreadsheetId: c.env.SPREADSHEET_ID,
    range: "A3:AI3",
  });
  c.text("Errors before this");
});

Results in the error described above.

2 Likes

same problem here using google service account

1 Like

Will this be fixed at some point?

I imagine the Node.js compat will be improved in future, yes. I’d recommend watching this issue on the workerd GitHub repository for updates:

1 Like