-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Unable to resolve module websocket in react native release mode #247
Comments
The node client requires the NPM |
I've added a note to the nodejs example about requiring "websocket". I'm not sure how this impacts react native though. |
This must be due to #243. @tiensonqin I'm not familiar with React Native, a few questions:
Thanks! |
Have updated 1.10.0-SNAPSHOT. I believe this should resolve the error. @tiensonqin 2 more questions if I may?:
|
@ptaoussanis Sorry about the delay.
|
@tiensonqin Thanks for the follow-up. Can anyone with Node experience perhaps point me to the docs for EDIT For context: need this to gracefully fail if the lib's not available. |
@DaveWM Alternatively: do we really need to call What exactly does the Finding it remarkably difficult to locate any docs on how |
@ptaoussanis Node's I think the simplest fix would be to only |
@DaveWM Thanks for the clarification.
That might work in this specific case but would prefer if we had something that's semantically equivalent to "load this library if it's available, otherwise just fail silently". Any idea how we achieve that if a try/catch doesn't seem to do it? |
AFAIK there's no way to do that without a try/catch in node unfortunately. Looks like the try/catch isn't working on react native because of this bug. The only workaround I can think of would be to write a macro that somehow determines whether the compile target is react native, and if it is omits the |
@DaveWM Thanks for digging into this. Looking into this a little more, it seems possible that this behaviour isn't even regarded as a bug. For example from: http://ruoyusun.com/2015/11/01/things-i-wish-i-were-told-about-react-native.html
As a temporary workaround, have rearranged the WebSocket search to try Better ideas still very much welcome. @tiensonqin Could you please try the latest SNAPSHOT and let us know if it's any better? |
@ptaoussanis The Thought about As for #248, really busy these days, have a baby daughter, and my first mobile app Lym on beta testing, I'll try to PR in next several days. By the way, sente works pretty strong in react native, really thank you for all the team! |
@tiensonqin Thanks for the confirmation, and congratulations on your new daughter :-) @DaveWM So if React's really doing static analysis, really not much we can do here besides:
I've no experience with Node or React Native so someone else may need to do the digging on this. If we can't find a solution, may need to back out #243 temporarily to keep from breaking anyone with v1.10, though that seems unfortunate. |
Okay, until the React Native team make a better option available - will just need React Native users to enable the |
How do I set that env variable? I'm using React Native and am still getting
in my output file. I've tried doing this:
And I've tried adding |
@seantempesta that refers to your command prompt.
and in fish (in fish config):
|
@levitanong: Thanks. This ended up working for me.
|
@ptaoussanis this System value approach makes it difficult to use Sente in a project with shadow-cljs with node and react-native targets. What if we passed an expression to (defn websocket-package-name
"Have to do this to get around React Native's static analysis.
https://github.com/facebook/react-native/issues/5079"
[web]
(str web "socket"))
(def ^:private ?node-npm-websocket_
"nnil iff the websocket npm library[1] is available.
Easiest way to install:
1. Add the lein-npm[2] plugin to your `project.clj`,
2. Add: `:npm {:dependencies [[websocket \"1.0.23\"]]}`
[1] Ref. https://www.npmjs.com/package/websocket
[2] Ref. https://github.com/RyanMcG/lein-npm"
(let [package-name (websocket-package-name "web")]
(delay ; Eager eval causes issues with React Native, Ref. #247,
(elide-require
(when (and node-target? (exists? js/require))
(try
(js/require package-name)
;; In particular, catch 'UnableToResolveError'
(catch :default e
;; (errorf e "Unable to load npm websocket lib")
nil))))))) I verified this works without advanced compile. Then the try/catch and |
Sente 1.9.0-beta2 works fine, 1.10.0-SNAPSHOT failed.
Error log:
UnableToResolveError: Unable to resolve module websocket from /Users/tienson/codes/index.ios.js: Unable to find this module in its module map or any of the node_modules directories under /Users/node_modules/websocket and its parent directories.
The text was updated successfully, but these errors were encountered: