polymergraphqlapollo-clientpolymer-3.xlit-html

Polymer 3, apollo-client, graphql and CommonJS modules


Dears,

I'm trying to make GraphQL work with Polymer 3 (or lit-html)

Trying to use apollo-client (which seems has adapters for polymer-elements and lit-html) and stuck with problem of importing CommonJS modules (i.e. module.export) in Polymer:

Uncaught SyntaxError: The requested module '../../graphql/language/visitor.js' does not provide an export named 'visit'

Correct me if I'm wrong, but if apollo-client provides apollo-client/polymer and apollo-client/lit-apollo this should work somehow. I tried to do it by included guides but got no success.


Solution

  • You'll have to use a build-time transform (e.g. a bundler like webpack) if you want to load a commonjs module via ES module import syntax.

    Commonjs modules (require(...), exports.foo = ...) are very different from ES modules, and usually require some pre-processing before they're loadable in the browser.