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

TypeError: Cannot assign to read only property '__esModule' of object '#<Object>' #4953

Closed
despaink opened this issue Jun 13, 2019 · 2 comments

Comments

@despaink
Copy link

despaink commented Jun 13, 2019

Intended outcome:
Send a mutation to a graphql endpoint with the following code:

const fetch = require('node-fetch');
const { ApolloClient, HttpLink, InMemoryCache } = require('apollo-boost');
const gql = require('graphql-tag');

const replaceItemsMutation = gqlmutation ReplacePlaylistItems($playlistItems: [PlaylistItemInput!]!) { replacePlaylistItems(playlistItems: $playlistItems) { id } }
async function createClient() {
const headers = await getAuthHeaders();

return new ApolloClient({
link: new HttpLink({
uri,
headers,
fetch
}),
cache: new InMemoryCache()
});
}

async function replacePlaylistItems(playlistItems) {
if (!client) {
client = await createClient();
}
await client.mutate({
mutation: replacePlaylistItemsMutation,
variables: { playlistItems }
})
}

module.exports = {
replacePlaylistItems
}

Actual outcome:
Executing the script in the command line with "node script.js" produces the following error:
Object.keys(ApolloClient__default).forEach(function (key) { exports[key] = ApolloClient__default[key]; });

TypeError: Cannot assign to read only property '__esModule' of object '#'
at path\node_modules\apollo-boost\lib\bundle.cjs.js:129:74
at Array.forEach ()
at Object. (path\node_modules\apollo-boost\lib\bundle.cjs.js:129:36)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)

Versions
Systems the script fails on:
System:
OS: Windows 10
Binaries:
Node: 10.15.1 - obscured path
npm: 6.9.0 - obscured path
Browsers:
Edge: 41.16299.15.0
npmPackages:
apollo-boost: ^0.3.1 => 0.3.1

System:
OS: Windows 7
Binaries:
Node: 9.9.0 - obscured path
npm: 5.6.0 - obscured path
npmPackages:
apollo-boost: ^0.3.1 => 0.3.1

System:
OS: macOS 10.14.5
Binaries:
Node: 8.10.0 - ~/.nvm/versions/node/v8.10.0/bin/node
npm: 5.6.0 - ~/.nvm/versions/node/v8.10.0/bin/npm
Browsers:
Chrome: 75.0.3770.80
Safari: 12.1.1
npmPackages:
apollo-boost: ^0.3.1 => 0.3.1

I am able to still get this script to work if I enclude:
const defineProperty = Object.defineProperty;
Object.defineProperty = function (exports, name) {
if (name === '__esModule') {
exports[name] = true;
return;
}
return defineProperty.apply(this, arguments)
}
at the top of the file that imports and uses the above code.

Other notes:
changing 'use strict' to 'use loose' in bundle.cjs.js allowed the script to work without errors.
I noticed that both \apollo-boost\lib\bundle.cjs.js and \apollo-boost\lib\index.js both have the following: Object.defineProperty(exports, '__esModule', { value: true }); (lines 3 and 2)
commenting out Object.defineProperty(exports, '__esModule', { value: true }); in bundel.cjs.js also allowed the script to work without errors.

@dylanwulf
Copy link
Contributor

This sounds a lot like #4843. Try upgrading apollo-boost to 0.4.1 and see if that fixes it

@benjamn
Copy link
Member

benjamn commented Jun 14, 2019

Closing because I strongly suspect @dylanwulf is correct. Please reopen this issue if updating apollo-boost to the latest version does not fix the problem!

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

No branches or pull requests

3 participants