Skip to content

Add CommonJs Support (SyntaxError: Unexpected token 'export') #383

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

Merged
merged 1 commit into from
Oct 12, 2020

Conversation

dchambers
Copy link
Contributor

@dchambers dchambers commented Oct 11, 2020

The apollo3-cache-persist module exported to npm is not CommonJS compatible at present, resulting in a SyntaxError: Unexpected token 'export' for me in Next.js.

The tsconfig.json file has module set to es2015, and this is presumably since Rollup (used to create a UMD module for the non-npm browser case) needs ES6 modules for tree-shaking to work. This change creates a fall-back CommonJS export (within lib/cjs) for any tooling that does not support the module key (also aliased as jsnext:main) in package.json.

@apollo-cla
Copy link

@dchambers: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@wtrocki
Copy link
Collaborator

wtrocki commented Oct 12, 2020

@@ -20,7 +20,7 @@
"bugs": "https://github.com/apollographql/apollo-cache-persist/issues",
"scripts": {
"build:browser": "browserify ./lib/bundle.umd.js -o=./lib/bundle.js && npm run minify:browser",
"build": "tsc -p .",
"build": "tsc -p . && tsc -p ./tsconfig.cjs.json",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to compile twice with duplicate source code?

@wtrocki
Copy link
Collaborator

wtrocki commented Oct 12, 2020

Going to merge this and release now.

@wtrocki wtrocki merged commit f0c43ca into apollographql:master Oct 12, 2020
@dchambers
Copy link
Contributor Author

Going to merge this and release now.

Thanks so much for the speedy response here @wtrocki! 🙏

@dchambers dchambers deleted the commonjs-support branch October 12, 2020 20:01
@wtrocki
Copy link
Collaborator

wtrocki commented Oct 12, 2020

Thank you for reminding me to release it

@dchambers
Copy link
Contributor Author

Hi @wtrocki, any chance I can get you to release this when you get a moment?

@wtrocki
Copy link
Collaborator

wtrocki commented Oct 15, 2020

Doing that now!

@wtrocki
Copy link
Collaborator

wtrocki commented Oct 15, 2020

[email protected]

@dchambers
Copy link
Contributor Author

[email protected]

Thanks @wtrocki 🙏

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

Successfully merging this pull request may close these issues.

3 participants