babel / babel-brunch

Brunch plugin for Babel
ISC License
69 stars 38 forks source link

SyntaxError: export declarations may only appear at top level of a module #66

Closed English3000 closed 5 years ago

English3000 commented 6 years ago

Repo

require.register("@absinthe/socket-relay/src/index.js", function(exports, require, module) {
  require = __makeRelativeRequire(require, {}, "@absinthe/socket-relay");
  (function() {
    // @flow

// @create-index

export {default as createFetcher} from "./createFetcher.js";
export {default as createSubscriber} from "./createSubscriber.js";
export {default as isSubscribed} from "./isSubscribed.js";
  })();
});

I need to comment out all files that use @absinthe/socket-relay or react-router-native (same error) to get the app to render.

The issue is Brunch generates require.register( and having export { inside the callback leads to a compilation error.

How do I fix this?

(If you clone this, uncomment environment.js or /screens/Router.js to generate a new build. Then in /priv/static/js/app.js, cmd + f for @absinthe/socket-relay or react-router-native respectively. Look a few lines down for an export { clause.)

English3000 commented 6 years ago

A person from Babel just posted:

so the problem is that the package that you're using, @absinthe/socket-relay/src/index.js, is published as ES6 and Babel is only running on your own local files

English3000 commented 6 years ago

The fix for @absinthe/socket-relay is to use "@absinthe/socket-relay/compat/cjs" in your files.