calvinmetcalf / rollup-plugin-node-builtins

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught TypeError: Cannot read property 'prototype' of undefined

binarykitchen opened this issue · comments

Happens when util.inherits(Duplex, Readable); is executed, see screenshot:

selection_009

To reproduce, just git clone https://github.com/binarykitchen/videomail-client/tree/feature/rollupjs and run yarn examples. Then you see that in the console.

considering that the line is inherits(Duplex, Readable); I think you're issue is that you aren't actually using this library

hmmm, if you think i am not using it, how can i exclude it then?

that is a more general rollup question, there might be a module replacer plugin or something that might rewrite readable-stream calls to just regular stream calls

ugh, that's probably new / out of my league. hints or examples how to replace this would be very welcome

@calvinmetcalf ok, what exactly would you replace with that alias plugin?

    alias({
      'Readable': 'what to put here??' <-----
    })

readable-stream:'stream' probably

@calvinmetcalf thanks but i am afraid, i am seeing this error with that change:

(670): node_modules/websocket-stream/stream.js🚨   Could not load stream (imported by /home/michael-heuberger/code/videomail-client/node_modules/websocket-stream/stream.js): ENOENT: no such file or directory, open 'stream'

for reference, this is the whole config:

export default {
  entry: 'src/index.js',
  moduleName: uppercamelcase(moduleName),
  sourceMap: 'inline',
  plugins: [
    replace({'process.env.NODE_ENV': JSON.stringify('development')}),
    progress(),
    stylusCssModules({output: false}),
    json({preferConst: true}),
    alias({
      'readable-stream': 'stream'
    }),
    commonjs(),
    buble(),
    builtins(),
    resolve({jsnext: true, browser: true}),
    globals(),
    filesize({showGzippedSize: false})
  ],
  targets: [{
    dest: packageInfo.main,
    format: 'iife'
  }]
}

not sure if the alias plugin should be moved further down?

commented

Apparently it's because rollup-plugin-alias resolves the path of the plugin, I've opened an issue about it since I run into the exact same issue... rollup/rollup-plugin-alias#33

For the time being I fork the packages I need and I replace 'readable-stream' with 'stream' manually...

have switched to webpack i am afraid ...

I'm seeing this error too. I'm also not using this package explicitly. My offending error is at:

util$3.inherits(Duplex$1, _stream_readable);

I'm using readable-stream as a dependency. And this is my rollup producing a browser target.

  {
    input: 'lib/index.js',
    output: {
      file: 'dist/index.browser.umd.js',
      format: 'umd',
      name: 'virtualfs'
    },
    plugins: [
      babel({
        babelrc: false,
        exclude: 'node_modules/**',
        runtimeHelpers: true,
        plugins: ['transform-object-rest-spread', 'transform-runtime', 'transform-class-properties'],
        presets: [
          'flow',
          ['env', {
            modules: false,
            targets: {
              browsers: ['last 2 versions']
            }
          }]
        ]
      }),
      resolve({
        preferBuiltins: false,
        browser: true
      }),
      commonjs({
        namedExports: {
          'node_modules/process/browser.js': ['nextTick']
        }
      })
    ]
  }

I just ended up finding related discussion in nodejs/readable-stream#237 So it seems I'm supposed to not use readable-stream at all. But I want to maintain stability for both node users and browser users.

If I do use this to resolve the rollup issue with readable-stream how does this interact with other polyfills that I already have? I have existing polyfills for buffer, process, path, events... etc. I would only want this to fix the stream issue.

it might interact weirdly, with other polyfills, but based on your config, you only have one for next tick

I ended converting to just using your polyfills @calvinmetcalf and switching from readable-stream to stream. I hope everything works.