Shopify / js-buy-sdk

The JS Buy SDK is a lightweight library that allows you to build ecommerce into any website. It is based on Shopify's API and provides the ability to retrieve products and collections from your shop, add products to a cart, and checkout.
https://shopify.github.io/js-buy-sdk
MIT License
990 stars 261 forks source link

webpack -p fails when shopify-buy is present in a project #373

Closed yantakus closed 7 years ago

yantakus commented 7 years ago

Just this one line import shopifyBuy from 'shopify-buy'; (I mean even without using it anywhere further) is enough for webpack -p to fail with the following error:

ERROR in 14.b62c90f89709f107e402.chunk.js from UglifyJs
Unexpected token: name (assign) [14.b62c90f89709f107e402.chunk.js:23263,4]

ERROR in 16.6b6ddd70b6f6c1552acc.chunk.js from UglifyJs
Unexpected token: name (assign) [16.6b6ddd70b6f6c1552acc.chunk.js:19893,4]

Any ideas on how to fix this?

minasmart commented 7 years ago

I would need a lot more information than that to know why webpack is blowing up.

Off the top of my head: are you configuring webpack to expect an ES module? Or a common JS module?

our main file is in common JS. If webpack is configured to look for a jsnext:main, we have an es module there.

If you wanna be super explicit you can import whichever of the following works:

shopify-buy/index -> commonjs shopify-buy/index.es -> es module shopify-buy/index.amd -> amd module shopify-buy/index.umd -> umd module

Hopefully this help!

yantakus commented 7 years ago

This is what I see inside node_modules/shopify-buy:

shopify js e2 80 94 lift-v2 2017-06-09 18-50-19

There's no files you mention.

yantakus commented 7 years ago

The version I use: "shopify-buy": "^0.7.1",. Did you expect me to use v1alpha?

yantakus commented 7 years ago

I'm using ES imports. As you can see above I'm using import shopifyBuy from 'shopify-buy'; and I have "modules": false option in .babelrc file.

yantakus commented 7 years ago

Using import shopifyBuy from 'shopify-buy/dist/shopify-buy.umd'; helped to solve the issue, thanks.

Why isn't the UMD build exported as default?

minasmart commented 7 years ago

Sorry, I was assuming this was the alpha. Glad you found a solution!

The UMD is not the default, because NPM convention is to support commonjs, and the UMD file is larger, so there's not a ton of advantage.