Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSergi Oca
7,981 PointsWhy is this code only working in this workspace?
I'm following along this and the code works in the workspace just fine. However, when I copy and paste the code for example in Codepen it just doesn't work and I get "Array.from is not a function.
I'm using 'use strict' on top of the page, I tried enabling Babel too but no luck.
What could be the reason for this?
3 Answers
aviralkulshreshtha
6,561 PointsYou need to use Babel to transpile the ES6 code to ES5, if you're running this in the browser. Although, you're supposed to run in this in your terminal. Install Node on your Linux/Mac(or god forbid, Windows) and run the files on node, not your browser. If you want to run it in a browser, then use Babel and it'll work.
If you're alien to all of that, just download a working es6-babel boilerplate from GitHub(do a google search for "es6 babel webpack boilerplate"), and you'd be able to run it in the browser. But given that you'd have to have node for that anyway, unless you explicitly need to make your code run in the browser, just install the newest node version and get playin in the console!
Tom Geraghty
24,174 PointsYou can always try it in a REPL such as: https://repl.it/languages/babel
This will run ES6 code in the browser for testing purposes.
Steven Parker
231,269 PointsYou might have some modules in the workspace that have not been transferred.
Workspaces have local storage to draw from, but Codepen projects do not. So if you transfer something you must be careful that you get all of the relevant parts.
You could try posting a snapshot of your workspace here and we could take a closer look.
Sergi Oca
7,981 PointsThe problem was on my end, I'm at work and I suspected that Chrome here wasn't allowed to update, sure enough a "chrome://version/" check showed that my version is 42. I think that's why I keep getting "Array.from()" is not a function with most things I try.
Scott Cook
16,877 PointsScott Cook
16,877 PointsI'm running it on node locally with a fresh install. It's ran everything in the course up until this point correctly, then I get this error:
Edit: I was running Ubuntu for Windows and switched back to Powershell and now it works. Weird.