Create-React-App build - “Uncaught SyntaxError: Unexpected token <”

后端 未结 9 1436
予麋鹿
予麋鹿 2020-12-10 10:35

I realize this question has been asked multiple times but nothing has worked for me...

I\'m trying to create a static build of a create-react-app projec

相关标签:
9条回答
  • 2020-12-10 11:06

    Thanks this helped me a lot. Just wanting to add to this with an example from a Create-React-App project that had the same solution: I received the same error after deploying to heroku.

    Uncaught SyntaxError: Unexpected token < after serve -s build

    For me the problem was in the packages.json file. The "homepage" parameter i gave was incorrect. Changing this to the correct heroku URL solved the issue.

    "homepage": "https://myapp.herokuapp.com/"
    

    Hope this addition is helpful.

    0 讨论(0)
  • 2020-12-10 11:11

    If you are deploying your client to S3, when deploying with react-deploy-s3, assign the distribution-id from CloudFront

    react-deploy-s3 deploy \
      --access-key-id XXXXXXXXXXXXXXXXX \
      --secret-access-key XXXXXXXXXXXXXXXXXXXXXXXX \
      --bucket XXXXXXX \
      --region us-east-1 \
      --distribution-id XXXXXXXXXXXXX                        <---
    
    0 讨论(0)
  • 2020-12-10 11:17

    I created a build version of react app using "npm run build". I have a server (node/express). I wanted to include the build in server side and deploy to heroku. What i did is copied build folder to server root folder and used code in server side startup file:

    app.get('/*', function (req, res, next) {
        if (!req.path.includes('api'))
            res.sendFile(path.join(__dirname, 'build', 'index.html'));
        else next();
    });
    
    

    I was getting the same error. So i just set the path for static contents at starting:

    var app = express();
    //here below
    app.use(express.static(path.join(__dirname, 'build')));
    
    

    And my static index.html was served fine and was able to find resources css and js.

    0 讨论(0)
提交回复
热议问题