apollo-client: Cannot set property default of #
Intended outcome:
I just tried to import the apolo boost in a node js environment that uses typescript.
import {ApolloClient} from 'apollo-boost'
Actual outcome:
TypeError: Cannot set property default of #<Object> which has only a getter
at Object.<anonymous> (h:\Private#2019\Project\_local\article-glow\core\node_modules\apollo-boost\lib\bundle.cjs.js:158:17)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (h:\Private#2019\Project\_local\article-glow\core\src\Backend\Sequence\After.ts:5:1)
at Module._compile (internal/modules/cjs/loader.js:722:30)
How to reproduce the issue:
install apollo-boost
and trying import
npm install --save apollo-boost
Versions
System:
OS: Windows 10
Binaries:
Node: 11.3.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.12.3 - ~\AppData\Roaming\npm\yarn.CMD
npm: 6.7.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 41.16299.15.0
npmPackages:
apollo-boost: ^0.4.0 => 0.4.0
apollo-cache-inmemory: ^1.6.0 => 1.6.0
apollo-link-http: ^1.5.14 => 1.5.14
apollo-server: ^2.4.8 => 2.5.0
apollo-server-express: ^2.4.8 => 2.5.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 57
- Comments: 17 (4 by maintainers)
Commits related to this issue
- Compile ESM bundle to CJS using TypeScript instead of Rollup. https://github.com/apollographql/apollo-client/issues/4843#issuecomment-495717720 Fixes #4843. — committed to apollographql/apollo-client by benjamn 5 years ago
- Fix apollo-boost https://github.com/apollographql/apollo-client/issues/4843#issuecomment-495585495 — committed to tvararu/mcrfe by tvararu 5 years ago
- Fix apollo-boost https://github.com/apollographql/apollo-client/issues/4843#issuecomment-495585495 — committed to tvararu/mcrfe by tvararu 5 years ago
- Compile ESM bundle to CJS using Babel instead of Rollup. https://github.com/apollographql/apollo-client/issues/4843#issuecomment-495717720 Fixes #4843. — committed to apollographql/apollo-client by benjamn 5 years ago
- Compile ESM bundle to CJS using Babel instead of Rollup. https://github.com/apollographql/apollo-client/issues/4843#issuecomment-495717720 Fixes #4843. — committed to apollographql/apollo-client by benjamn 5 years ago
- Compile ESM bundle to CJS using Babel instead of Rollup. (#4911) * Compile ESM bundle to CJS using Babel instead of Rollup. https://github.com/apollographql/apollo-client/issues/4843#issuecomment-... — committed to apollographql/apollo-client by benjamn 5 years ago
This should be fixed in
apollo-boost@0.4.1
(just released).Temporary workaround
import ApolloClient from "apollo-boost/lib/index";
I am having this issue as well using 0.4.0. Reverting back to 0.3.1 resolved my issue for the time being.
This appears to be an upstream bug in the Rollup CommonJS output for
apollo-boost/lib/bundle.cjs.js
.In order to compile
Rollup generates the following code:
However, because
apollo-client
also has adefault
export, thatdefault
export is mistakenly defined onexports
in theforEach
loop byObject.defineProperty
in a way that cannot simply be overridden by theexports.default = DefaultClient
assignment. That’s why you’re seeing the errorAccording to the ECMAScript specification, the
default
export should actually be excluded when doingexport * from "apollo-client"
. When I first learned about this gotcha, it surprised me too, but the TC39 committee (including myself) have reached a firm consensus on this behavior, and Rollup is violating the specification by copying over all exported properties ofapollo-client
.I will open other issues in the appropriate places, but I wanted to give everyone an update here first.
I just installed
0.4.1
and it fixed the issue (Y)I’m having a similar issue with Next.js & Apollo Client configuration ~ next-apollo, reverting back to old versions solved my issues for now.
I had the exact same issue with
0.4.0
, then I downgraded to0.3.1
then everything worked fineHad the issue with
apollo-boost -> 0.4.0
and went back to0.3.1
per @musemind’s post and it fixed the issue. I tried multiple config options, and even no config at all and the issue still remained.Just to expand on what @mattschoch suggested above, it might be a good idea to use
~
instead of^
, since^2.5.1
matches2.6.1
, but~2.5.1
only matches2.5.x
versions.Also having this issue with
new ApolloClient()
with an TypeScript + ReactNative + Expo setup. The importimport ApolloClient from 'apollo-boost'
alone does not cause any error. Reverting to0.3.1
does not help for me. Perhaps it’s an issue with TypeScript imports.Using the isolated packages / imports works for me: