Skip to content
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 TypeError: Cannot read property 'prototype' of undefined #31

Open
binarykitchen opened this issue Jun 24, 2017 · 16 comments
Open

Comments

@binarykitchen
Copy link

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.

@calvinmetcalf
Copy link
Owner

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

@binarykitchen
Copy link
Author

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

@calvinmetcalf
Copy link
Owner

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

@binarykitchen
Copy link
Author

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

@binarykitchen
Copy link
Author

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

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

@calvinmetcalf
Copy link
Owner

readable-stream:'stream' probably

@binarykitchen
Copy link
Author

@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?

@tex0l
Copy link

tex0l commented Oct 26, 2017

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...

@binarykitchen
Copy link
Author

have switched to webpack i am afraid ...

@CMCDragonkai
Copy link

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']
        }
      })
    ]
  }

@CMCDragonkai
Copy link

CMCDragonkai commented May 14, 2018

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.

@calvinmetcalf
Copy link
Owner

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

@CMCDragonkai
Copy link

CMCDragonkai commented May 14, 2018 via email

@calvinmetcalf
Copy link
Owner

calvinmetcalf commented May 14, 2018 via email

@CMCDragonkai
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants