Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import the named export 'ApolloLink' from non EcmaScript module #72

Closed
pleerock opened this issue Mar 2, 2018 · 12 comments
Closed
Labels

Comments

@pleerock
Copy link

pleerock commented Mar 2, 2018

After doing following:

import {createUploadLink} from "apollo-upload-client";

export const GraphqlClient = new ApolloClient({
    link: createUploadLink({ uri: "http://localhost:3000/graphql" }),
    cache: new InMemoryCache(),
});

I have these errors when building using webpack:

ERROR in ./node_modules/apollo-upload-client/lib/index.mjs
33:13-23 Can't import the named export 'ApolloLink' from non EcmaScript module (only default export is available)
 @ ./node_modules/apollo-upload-client/lib/index.mjs
 @ ./src/service/GraphqlClient.js
 @ ./src/component/AppComponent.js
 @ ./src/index.js

ERROR in ./node_modules/apollo-upload-client/lib/index.mjs
34:14-23 Can't import the named export 'selectURI' from non EcmaScript module (only default export is available)
 @ ./node_modules/apollo-upload-client/lib/index.mjs
 @ ./src/service/GraphqlClient.js
 @ ./src/component/AppComponent.js
 @ ./src/index.js

ERROR in ./node_modules/apollo-upload-client/lib/index.mjs
43:32-56 Can't import the named export 'selectHttpOptionsAndBody' from non EcmaScript module (only default export is available)
 @ ./node_modules/apollo-upload-client/lib/index.mjs
 @ ./src/service/GraphqlClient.js
 @ ./src/component/AppComponent.js
 @ ./src/index.js

ERROR in ./node_modules/apollo-upload-client/lib/index.mjs
45:8-26 Can't import the named export 'fallbackHttpConfig' from non EcmaScript module (only default export is available)
 @ ./node_modules/apollo-upload-client/lib/index.mjs
 @ ./src/service/GraphqlClient.js
 @ ./src/component/AppComponent.js
 @ ./src/index.js

ERROR in ./node_modules/apollo-upload-client/lib/index.mjs
53:18-41 Can't import the named export 'serializeFetchParameter' from non EcmaScript module (only default export is available)
 @ ./node_modules/apollo-upload-client/lib/index.mjs
 @ ./src/service/GraphqlClient.js
 @ ./src/component/AppComponent.js
 @ ./src/index.js

ERROR in ./node_modules/apollo-upload-client/lib/index.mjs
75:15-25 Can't import the named export 'Observable' from non EcmaScript module (only default export is available)
 @ ./node_modules/apollo-upload-client/lib/index.mjs
 @ ./src/service/GraphqlClient.js
 @ ./src/component/AppComponent.js
 @ ./src/index.js

ERROR in ./node_modules/apollo-upload-client/lib/index.mjs
76:34-57 Can't import the named export 'createSignalIfSupported' from non EcmaScript module (only default export is available)
 @ ./node_modules/apollo-upload-client/lib/index.mjs
 @ ./src/service/GraphqlClient.js
 @ ./src/component/AppComponent.js
 @ ./src/index.js

ERROR in ./node_modules/apollo-upload-client/lib/index.mjs
88:14-39 Can't import the named export 'parseAndCheckHttpResponse' from non EcmaScript module (only default export is available)
 @ ./node_modules/apollo-upload-client/lib/index.mjs
 @ ./src/service/GraphqlClient.js
 @ ./src/component/AppComponent.js
 @ ./src/index.js

Do you have any ideas in mind why I have following errors?

@pleerock
Copy link
Author

pleerock commented Mar 2, 2018

Issue changed, Ive updated

@pleerock pleerock changed the title File is empty when sending Can't import the named export 'ApolloLink' from non EcmaScript module Mar 2, 2018
@pleerock
Copy link
Author

pleerock commented Mar 2, 2018

Removing index.mjs file solves the issue, but apparently I cannot do it in real life.

@pleerock
Copy link
Author

pleerock commented Mar 2, 2018

Im using webpack4 btw

@jaydenseric jaydenseric added the bug label Mar 3, 2018
@jaydenseric
Copy link
Owner

Yes, this is an issue that intersects a few different things surrounding ESM and .mjs. I'll work on this this as soon as I can. The best solution is to PR apollo-link-http-common to properly support named imports with .mjs files.

@jaydenseric
Copy link
Owner

This should be fixed in v7.1.0.

Note that the lasting solution is for Apollo to support ESM properly, see apollographql/apollo-link#537. In the meantime, Webpack will display harmless, but annoying warnings like these due to our workarounds:

screen shot 2018-03-07 at 1 24 58 pm

screen shot 2018-03-07 at 1 25 14 pm

@pcjmfranken
Copy link

pcjmfranken commented Mar 7, 2018

It's actually completely failing to compile for me:

Failed to compile.

./node_modules/apollo-upload-client/lib/index.mjs
5:17-34 "export 'default' (imported as 'apolloLinkDefault') was not found in 'apollo-link'
 @ ./node_modules/apollo-upload-client/lib/index.mjs
 @ ./src/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8000 webpack/hot/dev-server babel-polyfill ./src

@gopeter
Copy link

gopeter commented Mar 7, 2018

Got the same compile error after upgrading to 7.1.0

@jaydenseric
Copy link
Owner

@pcjmfranken what version of Webpack are you using?

@pcjmfranken
Copy link

pcjmfranken commented Mar 7, 2018

"webpack": "^3.11.0"

Relevant parts of index.js

import { createUploadLink } from 'apollo-upload-client'

const apolloLinks = split(
  ({ query }) => {
    const { kind, operation } = getMainDefinition(query)
    return kind === 'OperationDefinition' && operation === 'subscription'
  },
  apolloWebSocketLink,
  apolloUploadClientLink,
  apolloHttpLink
)

const apolloClient = new ApolloClient({
  cache: apolloCache,
  link: ApolloLink.from([
    apolloStateLink,
    apolloLinks
  ])
})

The above code works with "apollo-upload-client": "^7.0.0-alpha.4"

@shamit6
Copy link

shamit6 commented Mar 7, 2018

Meanwhile I import index.js file directly:
import {createUploadLink} from 'apollo-upload-client/lib/index'

@tim-soft
Copy link

tim-soft commented Mar 7, 2018

I also get compilation errors, I'll have to roll it back for now

@jaydenseric
Copy link
Owner

I am cutting a new major release with a traditional .js setup until Apollo link packages provide native ESM. Until then it is too hard to support all environments and various versions of build tools with .mjs 😢

apollo-upload-server has been working great with .mjs and --experimental-modules so there are no plans to revert other packages to .js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants