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

Error module not found , key.json #188

Open
isaacdarcilla opened this issue Jan 24, 2024 · 4 comments
Open

Error module not found , key.json #188

isaacdarcilla opened this issue Jan 24, 2024 · 4 comments
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@isaacdarcilla
Copy link

Need help. I am trying to use App router here using NextJS.

Error says Cannot find module

error Error: Cannot find module 'C:\path\to\project\packages\frontend\public\google\client.json' at webpackEmptyContext (C:\path\to\project\packages\frontend\.next\server\app\api\captions\route.js:22:10)

Now, the client.json file is placed in public/google directory and I'm trying to access it in api route.ts

This is the code in route.ts

// app/api/captions/route.ts

import { google } from "googleapis";
import { authenticate } from "@google-cloud/local-auth";
import path from "path";

export async function GET() {

  const auth = await authenticate({
    keyfilePath: path.resolve("public", "google", "client.json"),
    scopes: ["https://www.googleapis.com/auth/youtube"],
  });

  google.options({ auth });
  
  console.log(auth);
}
@isaacdarcilla isaacdarcilla added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Jan 24, 2024
@nayyer28
Copy link

I am facing the same issue. Works fine in js but not ts

@isaacdarcilla
Copy link
Author

isaacdarcilla commented Jan 30, 2024

I am facing the same issue. Works fine in js but not ts

Was able to make this work by using google api client directly.

So instead of that, I did implement it like this,

import { google } from "googleapis";
import path from "path";

export async function GET(request: NextRequest) {

    const auth = new google.auth.GoogleAuth({
      keyFile: path.resolve("public", "google", "client.json"),
      scopes: [
        "https://www.googleapis.com/auth/youtube",
      ],
    });

    google.options({ auth: auth });
    
    console.log(auth);
 }

@deltaepsilon
Copy link

Can confirm. This breaks in a fresh TS project.

@deltaepsilon
Copy link

I got around it by using the Page Router. App Router will not work with this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants