· 2 min read

Rollup Error Encountered When Using Svelte with apollo-boost

This article was auto-translated from Chinese. Some nuances may be lost in translation.

I originally wanted to try playing around with Svelte and GraphQL to see how it felt. Apollo’s built-in Observable Query pairs really easily with reactive scenarios.

I imported ApolloClient inside Svelte:

import ApolloClient from 'apollo-boost';

Unexpectedly, after getting everything installed, Rollup failed to compile:

[!] Error: 'import' and 'export' may only appear at the top level
node_modules/symbol-observable/es/index.js (2:0)
1: /* global window */
2: import ponyfill from './ponyfill.js';
   ^
3:
4: var root;
Error: 'import' and 'export' may only appear at the top level
    at error (/Users/kalan/code/github-tool/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at Module.error (/Users/kalan/code/github-tool/node_modules/rollup/dist/shared/node-entry.js:9824:16)
    at tryParse (/Users/kalan/code/github-tool/node_modules/rollup/dist/shared/node-entry.js:9717:23)
    at Module.setSource (/Users/kalan/code/github-tool/node_modules/rollup/dist/shared/node-entry.js:10080:33)
    at Promise.resolve.catch.then.then.then (/Users/kalan/code/github-tool/node_modules/rollup/dist/shared/node-entry.js:12366:20)

I checked the issue and found similar problems reported elsewhere. I didn’t feel like digging deeper for a workaround right now since I had other ideas I wanted to finish first, so I had to retreat to my comfort zone and stick with React. Taking a quick note here to revisit later.

Related Posts

Explore Other Topics