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 trial

JavaScript React Basics (2018) 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,244 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:
    # 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', '*')
        SimpleHTTPRequestHandler.end_headers(self)

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,244 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