Reputation:
I'm using the 6to5 transpiler. When I try to use Object.assign() in my code, I get the following error: Uncaught TypeError: Object.assign is not a function
. How can I enable this functionality?
Upvotes: 1
Views: 5921
Reputation: 22923
In the latest release, where 6to5 has been renamed to Babel, you no longer need to do this. You can either configure it to use a polyfill or load the runtime. This is how I have set it up in gulp:
browserify({debug : true})
.transform(
// We want to convert JSX to normal javascript
babelify.configure({
// load the runtime to be able to use Object.assign
optional: ["runtime"]
})
);
You configuration should be pretty similar, no matter what tool you use. Using the package standalone would look like this:
require("babel").transform("code", { optional: ["runtime"] });
You can look at the documentation for runtime
. Remember to update to the latest version of babel, though! It updates very frequently.
Upvotes: 3
Reputation:
You have to include the browser-polyfill.js
file:
Available from the
browser-polyfill.js
file within the 6to5 directory of an npm release. This needs to be included before all your compiled 6to5 code. You can either prepend it to your compiled code or include it in a<script>
before it.NOTE: Do not
require
this via browserify etc, use6to5/polyfill
.
http://6to5.org/docs/usage/polyfill/
Upvotes: 1