camwest / react-slot-fill

Slot & Fill component for merging React subtrees together. Portal on steroids.
https://camwest.github.io/react-slot-fill/
Other
656 stars 27 forks source link

"ReferenceError: mitt is not defined" after upgrading to 1.0.2 #28

Closed dmr closed 7 years ago

dmr commented 7 years ago

After updating to 1.0.2 I receive import errors "ReferenceError: mitt is not defined"

image

Does this has to do with this commit? https://github.com/camwest/react-slot-fill/commit/f4087870aa3f74b86cb55f882e9f398586800256

MatthieuLemoine commented 7 years ago

The mitt import is missing in lib/rsf.es.js which is picked by webpack because of "module": "lib/rsf.es.js" in package.json.

If you set module to lib/rsf.js, you will have another error mitt is not a constructor as mitt also specify module in its package.json.

MatthieuLemoine commented 7 years ago

I think a rebuild should do the trick.

hannahjin commented 7 years ago

Having the same problem. I ran yarn build but that didn't resolve the issue.

MatthieuLemoine commented 7 years ago

@hannahjin You have to run the prepublish script instead.

MatthieuLemoine commented 7 years ago

Even with the import statement you will have the following error mitt is not a constructor.

The problem is that if you use the ES module rsf.es.js it will import the mitt ES module mitt.es.js (webpack will do that by default). So in Provider, it should be import mitt from 'mitt' instead of import * as mitt from 'mitt'.

But if you use rsf.js it will import mitt.js and then it should be import * as mitt from 'mitt'.

MatthieuLemoine commented 7 years ago

As a workaround, you can add the following to your webpack conf to force the usage of the umd build :

resolve : {
    mainFields : ['umd:main', 'module', 'main'],
},
dmr commented 7 years ago

So you say that my webpack config is the problem?

Is this a mitt issue or a react-slot-fill issue?

dmr commented 7 years ago

Sorry but I don't really understand the issue yet

MatthieuLemoine commented 7 years ago

The missing import is a react-slot-fill build issue.

The fact that it still doesn't work with the import is a mitt issue.

You can use the above workaround to make it work with webpack until this issue is fixed.

hannahjin commented 7 years ago

The prepublish script is not part of the package. mitt does appear in my yarn.lock, but I see that exact error in the picture.

MatthieuLemoine commented 7 years ago

31 should fix this issue.