emission
emission copied to clipboard
[Error] `$export is not a function` when using local node project
Premise:
I forked react-tracking, and want to point our react-tracking dependency to my local checkout.
What I did:
-
yarn add
(also triedyarn link
), and correctly point to my local checkout - reset the cache (
rm -rf node_modules
and reset cache on watchman andstart-packager
)
The error:
$export is not a function
This surfaces as soon as you run/load/refresh Emission. You do not need to load a page or click on anything for this to trigger.

File / line of code in question:

Other issues I've come across whilst doing this
Cache
This goes away by resetting cache across the board, and then goes back to export issue ^^^^^
Parsing...?
Got stuck in this state. Don't know why. Managed to remove it by recloning the local project, yarn installing there, clearing cache in emission, etc.

Thoughts
Originally, when searching the issue, you get the recommendation to ignore/exclude your node_modules
in your webpack.config
, however we don't use webpack in emission. Storybooks does, but if you run yarn start-packager
rather than yarn-start
, it doesn't use storybooks and the issue persists.
We then tried adding
"ignore": [
"node_modules/"
]
to the .babelrc file, which didn't help.
Next up was seeing if there were different version dependencies or if the issue was related to the project having its own node_modules
. We removed the node_modules
in the local project, so Emission would install them, but the same error surfaced again but in Emission's node_modules
directory, rather than react-tracking.
Lastly, when you change the file in question to add .default
to the import of $export
it works, as it's now recognised as a function rather than an object. However, the issue will then propagate to the next place where .default
isn't used.
Example:

Part 2
@damassi noted that react-tracking is using experimental babel features, also referred to a stage 1 proposal, and this may be incompatible with Emission.
When moving the source of react-tracking into the emission project, and then amending the syntax of index.js
to this:
import trackEvent from './trackEventMethodDecorator';
import trackingHOC from './trackingHoC';
import TrackingPropType from './TrackingPropType';
import withTracking, { TrackingContextType } from './withTrackingComponentDecorator';
export default trackingHOC;
export {
withTracking,
trackEvent,
TrackingPropType,
TrackingContextType,
};
It would run and compile locally without issues. When moving it back to a project dependency however, the same error pops up.
We then tried moving the runtime plugins over to emission, which would allow the project to compile, but broke things elsewhere as view controllers were blank (no loading, or anything).
@alloy thinks that it might have to do with npm linking and the RN bundler:
"If you’re trying to npm link
with a RN bundler setup like Emission’s, that won’t work because RN’s bundler has aways been unable to deal with symbolic links." GH issue/comment here.
There's still an open ticket about this on the extracted RN bundler
A suggestion is to use hard links, though macOS doesn’t have tooling out of the box to create hard links. Project here.
yarn link
and npm link
will alas not work with React Native’s bundler atm:
- https://github.com/facebook/react-native/issues/637#issuecomment-211553466
- https://github.com/facebook/metro-bundler/issues/1
As for your parse related issues, I have a suspicion (which may be completely wrong) that Emission’s bundler is trying to compile the node_modules
dir inside your react-native checkout. See if deleting the node_modules
directory fixes it to confirm if that’s the case.