Apollo-Client: Unexpected token import

Hi,

I use apollo-client in its newest version (1.0.0-rc.2) with meter (1.4.2.7) get the following error: “Unexpected token import”.

Yes, I use the ecmascript package (0.6.1) but for some reason it breaks here:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                     //
// node_modules/apollo-client/queries/queryTransform.js                                                                //
//                                                                                                                     //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                                       //
import { checkDocument } from './getFromAST';     // <------- here                                                     // 1
import { cloneDeep } from '../util/cloneDeep';                                                                         // 2
var TYPENAME_FIELD = {                                                                                                 // 3
    kind: 'Field',                                                                                                     // 4
    name: {                                                                                                            // 5
        kind: 'Name',                                                                                                  // 6
        value: '__typename',                                                                                           // 7
    },                                                                                                                 // 8
};       

My first assumption was, as apollo-client changed to use UMD and ES6 modules, the meteor build tool do not use the UMD bundle file from the node_modules folder, instead it uses the ES6 modules stuff. But it doesn’t make sense as it should already break using the index.js …

Any idea?

Are you importing something from a subdirectory?

Yeah, I do. Shouldn’t I?

Yeah - everything in Apollo is designed to be imported directly from the package root. If you import from a subdir, the package.json fields for browser/main/etc don’t apply.

Thx @sashko,

that was my issue.
I’ve upgraded apollo-client and used the old api of addTypename:

import { addTypenameToSelectionSet } from 'apollo-client/queries/queryTransform';

I’ve replaced it with the new option of ApolloClient:

ApolloClient({
    networkInterface: createMeteorNetworkInterface(),
    addTypename: true,
    connectToDevTools: isDevelopmentMode,
    dataIdFromObject: (result) => {
        if (result.id && result.__typename) {
            const dataId = result.__typename + result.id;
            return dataId;
        }
        return null;
    },
});

Now it works, thx!

1 Like