bhauman / bhauman/figwheel-repl

`(js/require cache-path)` causes Metro bundler to reject the compiled javascript

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Clojure
Stars
47
Forks
12
PR merge metrics
No merged PRs in 30d

Description

This isn't really an issue I expect to have a fix for right away, just something I wanted to bring up because you have React Native listed as a potential build target.

React Native rejects any require statements it can't verify when it goes to bundle your Javascript, so `require('./App.js')` is fine (because it can look up whether `App.js` exists in the project) but `require(cache_path)` is not.

Right not, you get an error that looks like:

```log
error: bundling failed: Error: out/figwheel/repl.js:Invalid call at line 239: require(cache_path)
at /Users/jberlage/cljs-native/FooBar/node_modules/metro/src/JSTransformer/worker.js:317:19
at Generator.next ()
at asyncGeneratorStep (/Users/jberlage/cljs-native/FooBar/node_modules/metro/src/JSTransformer/worker.js:75:24)
at _next (/Users/jberlage/cljs-native/FooBar/node_modules/metro/src/JSTransformer/worker.js:95:9)
```

This is caused by [`figwheel.repl/create-node-script-import-fn`](https://github.com/bhauman/figwheel-repl/blob/5a20d7a/src/figwheel/repl.cljc#L166), which gets left in builds with a browser target because it is `:export`ed.

Right now I'm using babel to transform other things in the CLJS build that don't play nice with React Native, so I'll probably do the same here. But I wanted to bring it up - you probably have better ideas on this topic than I do.

Contributor guide

No contributing guide indexed for this repository

Research direction

Inspect figwheel.repl/create-node-script-import-fn at the linked source location and compare its generated require(cache_path) with Metro's static require restriction. Reproduce the reported React Native bundling failure, then determine what browser-targeted output should be accepted by Metro without breaking the existing export.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure, javascript, react-native
Domain
mobile-dev, tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.