Uncaught ReferenceError: Buffer is not defined

Hello I'm getting the following error:
✘ [ERROR] service core:user:industries: Uncaught ReferenceError: Buffer is not defined

at null.<anonymous> (index.js:3223:11
✘ [ERROR] service core:user:industries: Uncaught ReferenceError: Buffer is not defined

at null.<anonymous> (index.js:3223:11
I have added compatibility_flags = [ "nodejs_compat" ] and am importing node:buffer.
import { Hono } from 'hono'
import { Buffer } from 'node:buffer';
globalThis.Buffer = Buffer; //✘ [ERROR] service core:user:industries: Uncaught ReferenceError: Buffer is not defined
const { Index, Document, Worker } = require("flexsearch");
import { parse } from 'csv-parse/sync'
import { Hono } from 'hono'
import { Buffer } from 'node:buffer';
globalThis.Buffer = Buffer; //✘ [ERROR] service core:user:industries: Uncaught ReferenceError: Buffer is not defined
const { Index, Document, Worker } = require("flexsearch");
import { parse } from 'csv-parse/sync'
Does anyone have any other suggestions? Thanks and kind regards
1 Reply
Ashley
Ashley2mo ago
I’d give this a read: https://blog.cloudflare.com/more-npm-packages-on-cloudflare-workers-combining-polyfills-and-native-code they recently released V2 of Node compat, but you’ll need to potentially bring your compatibility date forward (depending when you created your worker) - and pretty sure there’s no need for the node: prefix on V2
The Cloudflare Blog
More NPM packages on Cloudflare Workers: Combining polyfills and na...
Workers now supports more NPM packages and Node.js APIs using an overhauled hybrid compatibility layer.
Want results from more Discord servers?
Add your server