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

[Error] $export is not a function when using local node project #708

Open
mennenia opened this issue Aug 9, 2017 · 2 comments
Open

[Error] $export is not a function when using local node project #708

mennenia opened this issue Aug 9, 2017 · 2 comments

Comments

@mennenia
Copy link
Contributor

mennenia commented Aug 9, 2017

Premise:

I forked react-tracking, and want to point our react-tracking dependency to my local checkout.

What I did:

  • yarn add (also tried yarn link), and correctly point to my local checkout
  • reset the cache (rm -rf node_modules and reset cache on watchman and start-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:

screen shot 2017-08-09 at 18 22 37

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.

screen shot 2017-08-09 at 18 00 42

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:

screen shot 2017-08-09 at 18 25 08

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.

@mennenia mennenia changed the title $export is not a function when using local node project [Error] $export is not a function when using local node project Aug 10, 2017
@alloy
Copy link
Contributor

alloy commented Aug 10, 2017

yarn link and npm link will alas not work with React Native’s bundler atm:

@alloy
Copy link
Contributor

alloy commented Aug 10, 2017

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.

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

2 participants