I generated a Razzle React app using yarn create-razzle-app my-app
. I've deployed it to a nodeJS Elastic Beanstalk environment after building.
After hitting the elastic beanstalk url, I see no CSS applied to the site. Running the same server locally seems to work fine, so i'm wondering if there is more that needs to be done to configure the Razzle app for SSR on elastic beanstalk?
When inspecting the bundle.[HASH].js
and bundle.[HASH].css
, they both look like the following:
<!doctype html>
<html lang="">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<title>Welcome to Razzle</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/css/bundle.9638be3a.css">
<script src="/static/js/bundle.f03ddc0c.js" defer></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
This obviously causes errors, since it's not valid CSS or JS as indicated by the console output bundle.f03ddc0c.js:1 Uncaught SyntaxError: Unexpected token '<'
index
<!doctype html>
<html lang="">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<title>Welcome to Razzle</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/css/bundle.9638be3a.css">
<script src="/static/js/bundle.f03ddc0c.js" defer></script>
</head>
<body>
<div id="root"><div class="Home"><div class="Home-header"><h2>Welcome to Razzle</h2></div></div></div>
</body>
</html>
environment variables when building and on the Elastic Beanstalk configuration are:
NODE_ENV=production
PORT=8081
package.json
{
"name": "my-razzle-app",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"start": "razzle start",
"build": "razzle build",
"test": "razzle test --env=jsdom",
"start:prod": "NODE_ENV=production PORT=8081 node build/server.js"
},
"dependencies": {
"express": "^4.17.1",
"razzle": "^3.0.0",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-router-dom": "^5.1.2"
}
}
.ebextensions/nodecommand.config
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm run start:prod"