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

Edge, IE11 broken. Invalid bundling and exports. #438

Open
andrewmclagan opened this issue Sep 19, 2019 · 5 comments
Open

Edge, IE11 broken. Invalid bundling and exports. #438

andrewmclagan opened this issue Sep 19, 2019 · 5 comments
Milestone

Comments

@andrewmclagan
Copy link

andrewmclagan commented Sep 19, 2019

Currently bundling for Webpack environments / module environments is broken. In the Webpack build the library is build and transpiled - although in package.json it only points to the root (unstranspiled) /wpapi.js file. This is okay for most modern browsers as - only by chance - the features are supported.

Although this is not the case for Edge and IE11 both not supporting the object rest spread operator.

In summary the build is essentially broken for browsers environments - node works.

This long standing issue: #426 outlines the case with specific errors.

@andrewmclagan
Copy link
Author

andrewmclagan commented Sep 19, 2019

I have written up a PR that addresses these issues and also allows support for more environments, which is logical considering this library claims to be isomorphic - which is actually not the case at present. Also claims IE11 and edge support which is also not the case.

@andrewmclagan
Copy link
Author

In the end i abandoned the PR #439 as its going to take significant work to refactor the library. Id be happy to do it, just need assurance that this would be accepted first.

@andrewmclagan
Copy link
Author

andrewmclagan commented Sep 19, 2019

Workaround for those Webpack / bundler users who want support for Edge and IE 11 you can simply add the "browser" bundle (umd) as an external dependancy. Bundling it via package.json (node_modules) will break your build in IE and Edge.

Webpack e.g.

/**
 * Webpack config object
 * @return {Object}
 */
module.exports = (env, argv) => {
    // ...
    externals: {
      wpapi: 'WPAPI'
    },    
    // ...
};

Then import as usual:

import WPAPI from "wpapi";

:-(

My suggestion to the authors would be to write the library in ES then transpile to CJS and UMD. That way we are working from best case to worst case, smallest footprint.

@nsundberg
Copy link

Workaround for those Webpack / bundler users who want support for Edge and IE 11 you can simply add the "browser" bundle (umd) as an external dependancy. Bundling it via package.json (node_modules) will break your build in IE and Edge.

If you want to avoid editing the Webpack config and/or including it using a script tag you can also import the browser bundle directly:

import WPAPI from 'wpapi/browser/wpapi.min';

@andrewmclagan
Copy link
Author

andrewmclagan commented Oct 18, 2019

That works although not a great idea as it raises other issues

@kadamwhite kadamwhite added this to the 2.0 milestone Oct 21, 2019
andrewmclagan added a commit to andrewmclagan/docs that referenced this issue Nov 26, 2019
We recently release an early version of https://github.com/wp-headless/fetch that is now being used in production. 

It's not an easy decision to fragment the ecosystem when there are other offerings. We believe our approach is significantly different enough to warrant this risk. We did so for the following reasons:

* Long unresolved [browser issues](WP-API/node-wpapi#438)
* Bloated [packages size](https://bundlephobia.com/result?p=wpapi@0.12.1)
* No [tree-shakable](https://webpack.js.org/guides/tree-shaking/) ESM or CJS build available
* Opinionated API that attempts to do more then is needed.
* Lack of automated browser testing and coverage
* + more

wp-headless/fetch will be a valuable option to the community and therefore should be listed. Thanks! :-)
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

No branches or pull requests

3 participants