[ERROR] Could not resolve "node:buffer"

Hello, I'm having some issues with building my worker using:
compatibility_flags = [ "nodejs_compat" ]


I'm using a PNPM monorepo and the import i'm using is as follows:
import { Buffer } from 'node:buffer'


I have everything running and working in dev mode, however when I go to build the worker I get the following error:
> node ./build.js

✘ [ERROR] Could not resolve "node:buffer"

    src/index.ts:1:23:
      1 │ import { Buffer } from 'node:buffer'
        ╵                        ~~~~~~~~~~~~~

  The package "node:buffer" wasn't found on the file system but is built into node. Are you trying
  to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.


here is my build.js file with esbuild

import { build } from 'esbuild'

try {
  await build({
    entryPoints: ['./src/index.ts'],
    bundle: true,
    outdir: './dist/',
    sourcemap: true,
    minify: true,
    conditions: ['worker', 'browser'],
    outExtension: { '.js': '.mjs' },
    format: 'esm',
    target: 'esnext',
    plugins: [
    ]
  })
} catch (err) {
  process.exitCode = 1
}
Was this page helpful?