Trouble Building a Transaction (PTB)

I am working on a JavaScript project and I’m trying to build a PTB. After reading the sdk docs and multiple attempts at different build strategies, I keep running into the same error:

Transaction failed: Error: No provider passed to Transaction#build, but transaction data was not sufficient to build offline.

Has anyone run into this before? I would love some help here.

const bytes = await tx.build({ provider });
const signature = await keypair.signTransaction(bytes);
const result = await provider.executeTransactionBlock({
transactionBlock: bytes,
signature: signature,
});