title: Create react app + Django deployment Uncaught SyntaxError: Unexpected token <
body: <p>I've been trying to deploy an app to pythonanywhere but the page is just blank, because <strong>main.6f259c1b.js</strong> file throws error`</p>
  
  <blockquote>
    <p>Uncaught SyntaxError: Unexpected token &lt;</p>
  </blockquote>
  
  <p>`
  I've been following the instuctions on this article <a href="https://www.fusionbox.com/blog/detail/create-react-app-and-django/624/" rel="nofollow noreferrer">https://www.fusionbox.com/blog/detail/create-react-app-and-django/624/</a> and this <a href="https://www.techiediaries.com/create-react-app-django/" rel="nofollow noreferrer">https://www.techiediaries.com/create-react-app-django/</a>
  both articles suggest to create a view with following content</p>
  
  <pre><code>class FrontendAppView(View):
      """
      Serves the compiled frontend entry point (only works if you have run `yarn
      run build`).
      """
  
      def get(self, request):
          try:
              with open(os.path.join(settings.REACT_APP_DIR, 'build', 'index.html')) as f:
                  return HttpResponse(f.read())
          except FileNotFoundError:
              logging.exception('Production build of app not found')
              return HttpResponse(
                  """
                  This URL is only used when you have built the production
                  version of the app. Visit http://localhost:3000/ instead, or
                  run `yarn run build` to test the production version.
                  """,
                  status=501,
              ) 
  </code></pre>
  
  <p>and in app website/urls.py </p>
  
  <pre><code>urlpatterns = [
      url(r'^', FrontendAppView.as_view())
  ]
  </code></pre>
  
  <p>Those instructions don't work for me. It's something that related to <strong>pushState routing, react-routing</strong>, I don't know. My app works ok in development server in <strong>localhost:3000</strong>, it only seen in <strong>pythonanywhere</strong> and <strong>local apache server with mod_wsgi</strong>.
  This is my config of local apache(from Django documentation):</p>
  
  <pre><code>WSGIScriptAlias / /home/user/projects/myproject/myproject/wsgi.py
  WSGIPythonHome /home/user/.virtualenvs/myproject
  WSGIPythonPath home/user/projects/myproject/
  
  &lt;Directory /home/user/projects/myproject/myproject&gt;
  &lt;Files wsgi.py&gt;
  Require all granted
  &lt;/Files&gt;
  &lt;/Directory&gt;
  </code></pre>
  
  <p>This is root</p>
  
  <pre><code>DocumentRoot "/srv/http"
  </code></pre>
  
  <p>Part of my settings</p>
  
  <pre><code>REACT_APP_DIR = os.path.join(BASE_DIR, 'frontend')
  STATIC_URL = '/static/'
  
  STATIC_ROOT = 'static'
  
  STATICFILES_DIRS = [
      os.path.join(REACT_APP_DIR, 'build', 'static')
  ]
  </code></pre>
  
  <p>All software are latest release.
  Maybe this comment solves my problem, I just don't understand it. <a href="https://github.com/facebookincubator/create-react-app/issues/1812#issuecomment-286511320" rel="nofollow noreferrer">https://github.com/facebookincubator/create-react-app/issues/1812#issuecomment-286511320</a></p>
  
  <p>This is my localhost screenshot
  <a href="https://i.stack.imgur.com/0GChH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0GChH.png" alt="localhost screenshot"></a></p>
  
  <p>My project directory structure</p>
  
  <pre><code>├── api_v0
  │   ├── admin.py
  │   ├── apps.py
  │   ├── __init__.py
  │   ├── migrations
  │   ├── models.py
  │   ├── __pycache__
  │   ├── serializers.py
  │   ├── tests.py
  │   ├── urls.py
  │   └── views.py
  ├── myproject
  │   ├── __init__.py
  │   ├── local.py
  │   ├── __pycache__
  │   ├── settings.py
  │   ├── urls.py
  │   └── wsgi.py
  ├── frontend
  │   ├── build
  │   ├── node_modules
  │   ├── package.json
  │   ├── package-lock.json
  │   ├── public
  │   ├── README.md
  │   └── src
  ├── manage.py
  ├── requirements.txt
  ├── static
  │   ├── admin
  │   ├── css
  │   ├── js
  │   ├── media
  │   └── rest_framework
  └── website
      ├── admin.py
      ├── apps.py
      ├── __init__.py
      ├── management
      ├── middleware.py
      ├── migrations
      ├── models.py
      ├── __pycache__
      ├── tests.py
      ├── urls.py
      └── views.py
  </code></pre>