Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack 5+Process is not defined triggered by stream-browserify

I have to decode a CBOR encoded array using the cbor node module.

When i launch my command:

const decodedData = base45.decode(greenpassBody);
const output = pako.inflate(decodedData);
const results = cbor.decodeAllSync(output); // this line

this error is being triggered:

_stream_readable.js:529 Uncaught ReferenceError: process is not defined
    at emitReadable (_stream_readable.js:529)
    at addChunk (_stream_readable.js:303)
    at readableAddChunk (_stream_readable.js:280)
    at NoFilter.Readable.push (_stream_readable.js:241)
    at NoFilter.Transform.push (_stream_transform.js:139)
    at NoFilter._transform (index.js:220)
    at NoFilter.Transform._read (_stream_transform.js:177)
    at NoFilter.Transform._write (_stream_transform.js:164)
    at doWrite (_stream_writable.js:409)
    at writeOrBuffer (_stream_writable.js:398)

Triggered by the stram-browserify polyfill, necessary to use all of these packages in my web app.

As I read on web, I tried to install the process module in my package.json, then in my webpack config file i tryied in few ways:

fallback: {
  stream: require.resolve('stream-browserify'),
  util: require.resolve('util/'),
  zlib: require.resolve('browserify-zlib'),
  assert: require.resolve('assert/'),
  crypto: require.resolve('crypto-browserify'),
  fs: require.resolve('browserify-fs'),
  path: require.resolve('path-browserify'),
  process: require.resolve('process/browser'),  // <- this
}
alias: {
    'jquery-ui': path.resolve(__dirname, "./node_modules/jquery-ui"),
    'owl.carousel': path.resolve(__dirname, "./node_modules/owl.carousel"),
    modernizr$: path.resolve(__dirname, "./modernizrrc.js"),
    WOW: 'wowjs',
    process: "process/browser", // 1st try
    process: path.resolve(__dirname, "./node_modules/process/browser.js"), // 2nd try
},
    plugins: [
      // ...
      new webpack.DefinePlugin({
         process: "process/browser"
        "process.env": {
          ASSET_PATH: JSON.stringify(ASSET_PATH),
          NODE_ENV: JSON.stringify("development"),
          ENV: JSON.stringify("development"),
        },
      }),

With the DefinePlugin try, the error changed, it said browser is not defined.

Anyone knows how to correctly polyfill this module or if there are other ways to use the CBOR module?

Thanks so much

like image 372
Matteo Pietro Peru Avatar asked Sep 01 '26 20:09

Matteo Pietro Peru


1 Answers

SOLVED

the problem was that the process plugin must be provided, not defined:

it's

new webpack.ProvidePlugin({
  process: 'process/browser',
})

not

new webpack.DefinePlugin({
  process: 'process/browser',
}),
like image 156
Matteo Pietro Peru Avatar answered Sep 04 '26 11:09

Matteo Pietro Peru