Home > Blockchain >  React "Uncaught SyntaxError: Unexpected token <" whenn deploying my web app
React "Uncaught SyntaxError: Unexpected token <" whenn deploying my web app

Time:04-25

The app works just fine in development, but why I deploy it I see a blank page with the above error. All I do is 'npm run build' and then deploy the created library.

I don't know if it matters but I deploy it to a sub folder other than the root, so I add an htaccess file:

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.html$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myproject/index.html [L]

However I'm not sure it's what causing this. What could go wrong in this process?

CodePudding user response:

solved it, at least with a demo app:

Add this in the of index.html:

<base href="%PUBLIC_URL%/">

And to package.json:

  "homepage": "/mysubfolder/",

CodePudding user response:

I think you must first transform jsx with babel, browsers don't natively understand it.

  • Related