First off, the obvious answer that no one has provided, you need to install Babel into your application:
npm install babel --save
(or babel-core
if you instead want to require('babel-core/polyfill')
).
Aside from that, I have a grunt task to transpile my es6 and jsx as a build step (i.e. I don't want to use babel/register
, which is why I am trying to use babel/polyfill
directly in the first place), so I'd like to put more emphasis on this part of @ssube's answer:
Make sure you require it at the entry-point to your application, before anything else is called
I ran into some weird issue where I was trying to require babel/polyfill
from some shared environment startup file and I got the error the user referenced - I think it might have had something to do with how babel orders imports versus requires but I'm unable to reproduce now. Anyway, moving import 'babel/polyfill'
as the first line in both my client and server startup scripts fixed the problem.
Note that if you instead want to use require('babel/polyfill')
I would make sure all your other module loader statements are also requires and not use imports - avoid mixing the two. In other words, if you have any import statements in your startup script, make import babel/polyfill
the first line in your script rather than require('babel/polyfill')
.