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

Use babel transform runtime over babel polyfill #429

Closed

Conversation

evan-10e
Copy link
Contributor

@evan-10e evan-10e commented May 22, 2019

Problem

Projects that depend on babel-polyfill and fetch-mock will crash with the following error.

Solution

In short: Libraries should not be using babel-polyfill, but rather babel transform runtime.

Additional Context

Babel team members warn that if you are writing a library - babel polyfill should not be used because it can pollute the globals used by project owners.

If you are writing a library, you should not be using babel-polyfill. Having a library mutate the global state of the browser environment is not a good idea. If you need a standalone library you should be using babel-runtime via transform-runtime, or if you don't want to do that, you should make it a requirement that uses of your library load a polyfill first, and your code should assume it is there.

Logan Smyth (member and contributor of babel) babel/babel#4019 (comment)

As such, Fetch-mock's improper use of babel is causing projects to crash in this fashion. babel/babel#4019 (comment)

@wzph-10e
Copy link

+1

@wheresrhys
Copy link
Owner

Hi. Sorry for the slow response. Not had much time to maintain the library lately.

I agree with your appraisal, but don't think I can release this as a patch - babel polyfilling has been a discussion point in issues before, and I think this will break lots of people's tests. I don't want to deal with the fallout from that.

So I think this should be released as v8 of the library. Please could you search the repo (mainly docs) for mentions of v7 and update to say v7/8 https://github.com/wheresrhys/fetch-mock/search?q=v7&unscoped_q=v7. I will add a changelog note once released to explain what the difference between v7 and 8 is.

@ndelangen
Copy link

Could this be combined with an upgrade to core-js v3?

Or would this remove the need for core-js entirely?

Some users of storybook are hitting the core-js 3 incompatibility with this lib:
storybookjs/storybook#7445

I would be open to helping resolve this, Are you still working on this @evan-10e @wheresrhys ?

@evan-10e
Copy link
Contributor Author

@ndelangen I discovered that my bundle script was duplicated in the page head. Removing the dup solved the issue for me.

@wheresrhys
Copy link
Owner

wheresrhys commented Oct 26, 2019

v8.0.0-alpha.2 attempts to address this issue. Please leave a 👍 on the pull request #457 if your problem is solved, or alternatively leave a comment @evan-10e @ndelangen @wzph-10e

@wheresrhys wheresrhys closed this Oct 26, 2019
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.

4 participants