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
Uncaught ReferenceError: Buffer is not defined #13
Comments
I have also had this issue. Downgrading
https://stackoverflow.com/a/68806961/5001439 seems to indicate that upgrading Webpack may also be a solution. |
same issue here. @elsell how did solve this? cli output 👇 (click to expand)$ wrangler publish
Running npm install && npm run build
up to date, audited 611 packages in 3s
52 packages are looking for funding
run `npm fund` for details
3 moderate severity vulnerabilities
To address all issues, run:
npm audit fix
Run `npm audit` for details.
> worker-typescript-template@1.0.0 build
> webpack
asset worker.js 90.9 KiB [compared for emit] (name: main) 1 related asset
modules by path ./node_modules/@glenstack/ 21.7 KiB
modules by path ./node_modules/@glenstack/cf-workers-fetch-helpers/dist/*.js 6.52 KiB 6 modules
modules by path ./node_modules/@glenstack/cf-workers-discord-bot/dist/*.js 11.8 KiB
./node_modules/@glenstack/cf-workers-discord-bot/dist/index.js 1.28 KiB [built] [code generated]
./node_modules/@glenstack/cf-workers-discord-bot/dist/authorize.js 1.26 KiB [built] [code generated]
./node_modules/@glenstack/cf-workers-discord-bot/dist/interaction.js 2.78 KiB [built] [code generated]
./node_modules/@glenstack/cf-workers-discord-bot/dist/types.js 2.64 KiB [built] [code generated]
./node_modules/@glenstack/cf-workers-discord-bot/dist/setup.js 3.87 KiB [built] [code generated]
./node_modules/@glenstack/cf-workers-router/dist/index.js 3.33 KiB [built] [code generated]
./src/index.ts 1.02 KiB [built] [code generated]
./node_modules/tweetnacl/nacl-fast.js 60.5 KiB [built] [code generated]
crypto (ignored) 15 bytes [built] [code generated]
webpack 5.40.0 compiled successfully in 1299 ms
Build completed successfully!
Error: Something went wrong with the request to Cloudflare...
Uncaught ReferenceError: Buffer is not defined
at line 357 in btoa
at line 361 in exports.authorization
at line 222 in __webpack_modules__../node_modules/@glenstack/cf-workers-discord-bot/dist/setup.js.exports.setup
at line 68 in __webpack_modules__../node_modules/@glenstack/cf-workers-discord-bot/dist/index.js.exports.createSlashCommandHandler
at line 3073
at line 3083
at line 3085
[API code: 10021] |
Hi @chocnut maybe it will help you import { encode } from '@cfworker/base64url';
if (typeof Buffer === 'undefined' && typeof global !== 'undefined') {
global.Buffer = {
// @ts-ignore
isBuffer: s => typeof s === 'string',
// @ts-ignore
from: s => ({ toString: (m) => m === 'base64' ? encode(s).toString() : (m || '') }),
// @ts-ignore
byteLength: s => s.length,
};
} |
I forked this project and applied the fix you suggested. I had to fix a reliance on Buffers in one more place, but now it works! https://github.com/Code6226/glenstack/tree/master/packages/cf-workers-discord-bot |
When executing
wrangler publish
I'm getting a Buffer is undefined.The text was updated successfully, but these errors were encountered: