Razzle: Error in deployment (digitalocean, nginx)

Created on 1 Aug 2017  路  8Comments  路  Source: jaredpalmer/razzle

Hi, I just started with razzle, and created a project with default template. it works fine in my localhost. I deployed it on digitalocean droplet.

I'm getting following error
client.95ca56a2.js:1 Uncaught SyntaxError: Unexpected token < in client.95ca56a2.js:1

Also images are not loading. Any idea?

Most helpful comment

@cca313 you'll need to manually set the RAZZLE_PUBLIC_DIR environment variable to "./build/public" in whatever build environment you're using. So if you're using Jenkins you'll need to configure the variable in the jenkins settings. Or if you're building inside a docker image you can set it in the dockerfile with ENV RAZZLE_PUBLIC_DIR=./build/public

All 8 comments

I had this error too, it has to do with the way the env variables are set when building.

When you do a build, the public path is set from the environment variable 'RAZZLE_PUBLIC_DIR'.

If you're building on Windows it inserts the absolute path so when you then move to deploy it's no longer valid, so express ignores the public path and serves everything requested as the HTML. Thus '<' is an unexpected token in a script file.

I got around this by creating a .env file, adding 'RAZZLE_PUBLIC_DIR=./build/public', re-building and then deploying.

I'm not sure if this is as intended.

This tripped me up so bad, our jenkins instance spins up a separate container for the build process and this environment variable wasn't being persisted to the docker image that actually runs the app. Probably should have a default of ./build/public if not otherwise overwritten by the build

@jtyler258 hi~ i also got this problem, do you have any solutions?

@cca313 you'll need to manually set the RAZZLE_PUBLIC_DIR environment variable to "./build/public" in whatever build environment you're using. So if you're using Jenkins you'll need to configure the variable in the jenkins settings. Or if you're building inside a docker image you can set it in the dockerfile with ENV RAZZLE_PUBLIC_DIR=./build/public

@jtyler258 thank you so mcuh~ it's working !

I have the issue that my static assets files are not loading when creating build on digital ocean droplet
and also my routes are not working

I do this to address this problem but I wish I could find a better way :

.use(
    express.static(
      process.env.NODE_ENV === 'production'
        ? path.join(__dirname, './public')
        : process.env.RAZZLE_PUBLIC_DIR
    )

after your app is build (sudo yarn build) just use:
pm2 restart <pm2 process name>

it may solve this problem (at least it helps me in DO Droplet)
cheers

Was this page helpful?
0 / 5 - 0 ratings

Related issues

howardya picture howardya  路  5Comments

MaxGoh picture MaxGoh  路  4Comments

mhuggins picture mhuggins  路  3Comments

knipferrc picture knipferrc  路  5Comments

dizzyn picture dizzyn  路  3Comments