Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Don't require react-dom #42

Closed
kasper573 opened this issue Apr 27, 2016 · 11 comments
Closed

Don't require react-dom #42

kasper573 opened this issue Apr 27, 2016 · 11 comments

Comments

@kasper573
Copy link

kasper573 commented Apr 27, 2016

I use a custom react renderer that is not targeting the DOM thus I don't have the react-dom package in my project at all. This ends up giving me this error:

ERROR in ./~/mobx-react/index.js
Module not found: Error: Cannot resolve module 'react-dom' in D:\Code\symphony\node_modules\mobx-react
 @ ./~/mobx-react/index.js 198:8-71

Looking at mobx-react/index.js it doesn't look like react-dom is critical. How about making the package optional and permanently disabling your developer tools unless you have react-dom available?

A future improvement could be to support devtools with an arbitrary react renderer.

@mweststrate
Copy link
Member

Cool :) Could you check whether import {observer} from "mobx-react/native" works for you? In React Native the DOM isn't available either, so in the native build the dependency is stripped out. I think there is nothing React Native specific in there, so it might work out of the box in your case.

@kasper573
Copy link
Author

That produces the same problem since it instead of react-dom requires react-native. Since I have a custom renderer, I have neither.

ERROR in ./~/mobx-react/native.js
Module not found: Error: Cannot resolve module 'react-native' in D:\Code\symphony\node_modules\mobx-react
 @ ./~/mobx-react/native.js 198:8-65

@mweststrate
Copy link
Member

Ok, I'll setup a "mobx-react/no-dom" build in the next few days. In the
meantime you could try testing with all the ReactDOM stuff stripped out (if
you didn't do that already). Shouldn't be that much.

Op wo 27 apr. 2016 om 20:07 schreef Kasper Sandin <notifications@github.com

:

That produces the same problem since it instead of react-dom requires
react-native. Since I have a custom renderer, I have neither.

ERROR in .//mobx-react/native.js
Module not found: Error: Cannot resolve module 'react-native' in D:\Code\symphony\node_modules\mobx-react
@ ./
/mobx-react/native.js 198:8-65


You are receiving this because you commented.

Reply to this email directly or view it on GitHub
#42 (comment)

@kasper573
Copy link
Author

What I did to work around it was to just add an empty module named "react-dom.js" to node_modules. After that mobx was able to run fine!

@mweststrate
Copy link
Member

I just pushed a patch to master. Would you mind testing it by cloning this repo and after that, in your own repo, run npm install <checkoutpath>, and use the mobx-react/custom as import.

@mweststrate mweststrate reopened this Apr 30, 2016
@kasper573
Copy link
Author

kasper573 commented May 1, 2016

It works fine! Thanks for the quick support!

I'm not a big fan of patches being used this way though, but that's a question for another issue :). GG~

@Niryo
Copy link

Niryo commented Sep 3, 2017

@mweststrate can you explain in more details what should I do in order to eliminate this problem?
Im getting:
webpackHotDevClient.js:233 Error in ../test/~/mobx-react/index.js Module not found: 'react-dom' in /Users/niryo/git/test/node_modules/mobx-react

The error comes from this line:
@ ../test/~/mobx-react/index.js 2:116-136

I tried using: import { observer } from 'mobx-react/custom';
but it doesn't work.

@mweststrate
Copy link
Member

mweststrate commented Sep 4, 2017 via email

@Niryo
Copy link

Niryo commented Sep 7, 2017

@mweststrate What is the actually difference between the different renderers?
Is it only for development purpose? what will be the implications of using mobx-react/custom.js?
Im building a library that would be used from both react and react-native projects, and Im exposing mobx-react observer func.
what is the suggested way to do this? exposing observer from mobx-react/custom?

@mweststrate
Copy link
Member

mweststrate commented Sep 7, 2017 via email

@ProteanDev
Copy link

import { observer } from 'mobx-react/custom' Does work! Thanks! :)

@mobxjs mobxjs locked as resolved and limited conversation to collaborators Aug 1, 2019
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

4 participants