Compile some code below:
async function sleep(timeout) {
return new Promise((resolve, reject) => {
setTimeout(function () {
resolve();
}, timeout);
});
}
(async function () {
console.log('Do some thing, ' + new Date());
await sleep(3000);
console.log('Do other things, ' + new Date());
})();
Compile successfully, but error occurs in browser:
Uncaught TypeError: (0 , _typeof3.default) is not a function
Use Babel6 and compile the code, it worked in NodeJS. And, how to make it work well in browser with webpack
In my case, I added the following to my webpack config “module.loaders”:
For completeness, my full webpack config looks like:
When I add the exclusion to node_modules/ everything works as expected.
if anyone is still having issues with this make sure that the exclude does note contain quotes, i.e. “/node_modules/” or ‘/node_modules/’ . there is a lot of examples and boilerplate code like this, so I was still getting this compile error, because webpack as ignoring the exclude item on the loaders array. Thankfully I got some help on the babel slack channel! I hope that helps someone going bananas like I was before 😀