-
Notifications
You must be signed in to change notification settings - Fork 116
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
Conversation
@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/ |
Strange. We have react native example that build fine: https://github.com/apollographql/apollo-cache-persist/blob/master/examples/react-native/App.tsx#L14 (Web example uses source code import. |
@@ -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", |
There was a problem hiding this comment.
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?
Going to merge this and release now. |
Thanks so much for the speedy response here @wtrocki! 🙏 |
Thank you for reminding me to release it |
Hi @wtrocki, any chance I can get you to release this when you get a moment? |
Doing that now! |
Thanks @wtrocki 🙏 |
The
apollo3-cache-persist
module exported to npm is not CommonJS compatible at present, resulting in aSyntaxError: Unexpected token 'export'
for me in Next.js.The
tsconfig.json
file hasmodule
set toes2015
, 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 (withinlib/cjs
) for any tooling that does not support themodule
key (also aliased asjsnext:main
) inpackage.json
.