TypeError while trying to use external package
Answered
Spectacled Caiman posted this in #help-forum
Spectacled CaimanOP
Hey. I am trying to import these packages:
When I try to do this, I get the following error:
I know this package well, and I am sure it is not the packages fault. It works for everyone else. I think this might be related to how webpack imports packages. I have attached the full trace and the test code I'm trying to run.
I can import the class fine, but it errors when I actually try to do anything with the class.
import { Client, ClientMode } from "@buape/carbon"When I try to do this, I get the following error:
TypeError: Cannot read properties of undefined (reading 'Base')I know this package well, and I am sure it is not the packages fault. It works for everyone else. I think this might be related to how webpack imports packages. I have attached the full trace and the test code I'm trying to run.
import { NextResponse } from "next/server";
import { Client, ClientMode } from "@buape/carbon"
export async function GET() {
const client = new Client({
clientId: "xxxxxxxxxxxxxxxxxxxxxx",
publicKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
mode: ClientMode.Web
}, [])
return NextResponse.json({ "message": "Test" })I can import the class fine, but it errors when I actually try to do anything with the class.
Answered by Spectacled Caiman
Turbopack appears to fix this issue, and it only happens in dev, prod is fine.
3 Replies
Field Spaniel
Is there any reason to use the web mode? According to the documentation there is a special mode for working with Next.js
https://carbon.buape.com/carbon/getting-started/nextjs
https://carbon.buape.com/carbon/getting-started/nextjs
@Field Spaniel Is there any reason to use the web mode? According to the documentation there is a special mode for working with Next.js
https://carbon.buape.com/carbon/getting-started/nextjs
Spectacled CaimanOP
I have already tried that. I was using it so I can do some pre-processing before Carbon handles it, but it looks like I can do that with that mode anyway.
Spectacled CaimanOP
Turbopack appears to fix this issue, and it only happens in dev, prod is fine.
Answer