absinthe-graphql / absinthe-socket

Core JavaScript support for Absinthe WS-based operations
MIT License
149 stars 75 forks source link

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

Closed English3000 closed 6 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";
  })();
});

Literally copied & pasted environment.js & absinthe.js code from "Craft GraphQL APIs in Elixir with Absinthe" source code.

In the book, they put the frontend in a separate repo.

English3000 commented 6 years ago

Update: I got my app to render by commenting out my entire environment.js

// import { createFetcher, createSubscriber } from "@absinthe/socket-relay";
// import { Environment, Network, RecordSource, Store } from "relay-runtime";
// import absintheSocket from "./absinthe";
//
// export default new Environment({ network: Network.create( createFetcher(absintheSocket),
//                                                           createSubscriber(absintheSocket) ),
//                                  store: new Store(new RecordSource()) });

Also, react-router-native has the same issue. From what I've gleaned through searches, the issue may have to do with Babel 6 not transpiling the export statements nested within functions..?

Regardless, I still need a fix so I can use createFetcher and createSubscriber

English3000 commented 6 years ago

Tried

const createFetcher = require("@absinthe/socket-relay").createFetcher;
const createSubscriber = require("@absinthe/socket-relay").createSubscriber;

Doesn't work

English3000 commented 6 years ago

This is also an issue with react-router-native. I think what's causing the bug is the use of export {...} from ...

English3000 commented 6 years ago

In Google Chrome, the error (for this exact same issue) is

Uncaught SyntaxError: Unexpected token export

English3000 commented 6 years ago

To the best of my knowledge, this issue is being caused by how babel-brunch compiles your /src/index.js

I have opened an issue with them: https://github.com/babel/babel-brunch/issues/66

mgtitimoli commented 6 years ago

I guess the issue you are experiencing is because of this line, it should point to "compat/cjs/index.js" as the other packages...

Don't you mind trying to import from @absinthe/socket-relay/compat/cjs, and tell me how it went?

English3000 commented 6 years ago

IT WORKED!!!!!

mgtitimoli commented 6 years ago

Great @English3000!

I will add this to the tasks I need to acomplish for the next release, thanks for having taken the time to report this!

Happy coding!