Mobx: Multiple mobx instances active in production builds

Created on 21 Jul 2018  路  3Comments  路  Source: mobxjs/mobx

I have an issue

Whenever I use mobx in a production build, I receive the following error:

[mobx] There are multiple mobx instances active. This might lead to unexpected results.

I've been through https://github.com/mobxjs/mobx/issues/1082 and you can see some attempts I made at fixing it in this repo here.

I added a fakeprod build so we can actually see the error message instead of the obfuscation warning.
For hosting, I'm using Nginx on Centos7.5.

Most helpful comment

So, after following all the guides and issues, I realized not one of them could save me from myself. I'm using a neat little plugin, HtmlWebpackPlugin,

new HtmlWebpackPlugin({ template: PATHS.app + '/index.html' }),

which adds a line to your index.html file to reference your bundle. Because I was using a template which already had this line, it was double loading the bundle.

<script src="/static/bundle.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="static/bundle.js"></script>

Lucky for me, Mobx was all over it and informed me that something was wrong. This discovery has cleaned up all of the issues I had.

Thanks again @mweststrate for your help here and on Gitter. Mobx is a beautiful library.

All 3 comments

Tried to checkout your project, but I think the public stuff is missing. I cat build errors on yarn prod

My mistake. I fixed the repo. I wanted to keep most of my loaders just in case they were influencing this issue at all.

So, after following all the guides and issues, I realized not one of them could save me from myself. I'm using a neat little plugin, HtmlWebpackPlugin,

new HtmlWebpackPlugin({ template: PATHS.app + '/index.html' }),

which adds a line to your index.html file to reference your bundle. Because I was using a template which already had this line, it was double loading the bundle.

<script src="/static/bundle.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="static/bundle.js"></script>

Lucky for me, Mobx was all over it and informed me that something was wrong. This discovery has cleaned up all of the issues I had.

Thanks again @mweststrate for your help here and on Gitter. Mobx is a beautiful library.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mehdi-cit picture mehdi-cit  路  3Comments

joey-lucky picture joey-lucky  路  3Comments

thepian picture thepian  路  3Comments

hellectronic picture hellectronic  路  3Comments

cafreeman picture cafreeman  路  4Comments