1

I am trying to host my app on DigitalOcean and getting it running with pm2 but run into this error:

/home/bcavenagh/social/src/index.js:1
(function (exports, require, module, __filename, __dirname) { import React from 'react';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:27:21)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)

I can get everything to run when using npm start but it doesnt work for pm2. In npm I am running from the ~/social folder but for pm2 I cd into ~/social/src and run:

pm2 start index.js

How do I get past this error?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
Ben Cavenagh
  • 608
  • 1
  • 6
  • 22

1 Answers1

1

You must compile/build your application, if not done so.

It will create a build folder (assuming you are using default configs with create-react-app), then you must point pm2 to the appropriate file (bundle.js or whatever you have) in that folder.

PM2 also supports running npm start command now. Checkout this question. What i usually do is, write a sh file, which updates code, does npm install and then at last runs pm2 command, for all deployments, which is similar to this answer in the previous link.

Neeraj Kumar
  • 226
  • 4
  • 18