Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React Basics First Steps in React Understanding JSX

Cannot get past getting babel to work on my Windows 10 computer

I keep getting the following error ever since I got to the part of adding babel in the video:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:<file location>. (Reason: CORS request not http)

I installed python 3 onto my pc to attempt the other post's answer of "python -m SimpleHTTPServer", but it isn't working for me.

1 Answer

Gergely Bocz
Gergely Bocz
14,219 Points

Hi Carlos!

Keep in mind when reading my answer, that i'm not familiar with python as all my experience comes from javascript, and i haven't tested my solutions! Nevertheless, i hope they can help you!

While browsing the web, i found out that the python http server requires additional settings, therefore additional code to to enable CORS. The first example should work with python 3, but just in case i'll share the link to another.

Here is the first example by link and by code:

#!/usr/bin/env python

# Usage: python cors_http_server.py <port>

    # try to use Python 3
    from http.server import HTTPServer, SimpleHTTPRequestHandler, test as test_orig
    import sys
    def test (*args):
        test_orig(*args, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
except ImportError: # fall back to Python 2
    from BaseHTTPServer import HTTPServer, test
    from SimpleHTTPServer import SimpleHTTPRequestHandler

class CORSRequestHandler (SimpleHTTPRequestHandler):
    def end_headers (self):
        self.send_header('Access-Control-Allow-Origin', '*')

if __name__ == '__main__':
    test(CORSRequestHandler, HTTPServer)

And here is a link to the second example.

I hope it solves your problem! If not, try to ping someone else, who has experience with python!

Good luck, Gergő

Gergely Bocz
Gergely Bocz
14,219 Points

Also I have just realized based on the topic that you don't necessarily need python http-server.

If the examples above don't work, simply try adding the node package 'http-server' with 'npm install http-server' and run the server from the command line with the command: 'http-server [path/to/project/folder]. Here is the documentation for that: NPM http-server