Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Inheriting AMD/UMD classes when using AMD #150

Closed
viveleroi opened this issue Dec 14, 2016 · 2 comments
Closed

Inheriting AMD/UMD classes when using AMD #150

viveleroi opened this issue Dec 14, 2016 · 2 comments

Comments

@viveleroi
Copy link

Repo: https://github.com/viveleroi/rollup-amd-inherit-bug

I have a class which extends EventEmitter2, and they distribute umd. When our bundle is used with requirejs/AMD, the createCommonjsModule doesn't return anything.

Our source can simply be this:

import EventEmitter2 from 'eventemitter2';

export default class Test extends EventEmitter2 {}

In EventEmitter2 code, and in the bundled output, we get:

if (typeof define === 'function' && define.amd) {
     // AMD. Register as an anonymous module.
    define(function() {
      return EventEmitter;
    });
  }
...

Problem is, the createCommonjsModule doesn't handle this. The output assigns the returned value of that method, but in this case, it's undefined.

var eventemitter2 = createCommonjsModule(...
// => undefined

So when eventemitter2 is passed to the inherits call (inherits(Test, _EventEmitter);) it throws an error Super expression must either be null or a function, not object

@Rich-Harris
Copy link
Contributor

Good news! This is fixed in 6.0.0, via #144 – just tested the repro and if you update this plugin it should all work.

@viveleroi
Copy link
Author

I missed that was a duplicate, my bad. Glad to hear, I'll try it out.

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

No branches or pull requests

2 participants