1

I recently created a new EBS environment using Node.js 14 as my old environment is deprecated. Unfortunately, I'm running into the error below:

Jul 27 22:34:53 ip-172-31-42-207 web: error TS5033: Could not write file '/var/app/current/build/server/validation.js.map': EACCES: permission denied, open '/var/app/current/build/server/validation.js.map'.
Jul 27 22:34:53 ip-172-31-42-207 web: error TS5033: Could not write file '/var/app/current/build/triggers/Triggers.js': EACCES: permission denied, open '/var/app/current/build/triggers/Triggers.js'.
Jul 27 22:34:53 ip-172-31-42-207 web: error TS5033: Could not write file '/var/app/current/build/triggers/Triggers.js.map': EACCES: permission denied, open '/var/app/current/build/triggers/Triggers.js.map'.
Jul 27 22:34:53 ip-172-31-42-207 web: npm ERR! code ELIFECYCLE
Jul 27 22:34:53 ip-172-31-42-207 web: npm ERR! errno 2
Jul 27 22:34:53 ip-172-31-42-207 web: npm ERR! ballotbox-server@0.0.1 start: `tsc && node build/index.js`
Jul 27 22:34:53 ip-172-31-42-207 web: npm ERR! Exit status 2
Jul 27 22:34:53 ip-172-31-42-207 web: npm ERR!
Jul 27 22:34:53 ip-172-31-42-207 web: npm ERR! Failed at the ballotbox-server@0.0.1 start script.
Jul 27 22:34:53 ip-172-31-42-207 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Jul 27 22:34:53 ip-172-31-42-207 web: npm ERR! A complete log of this run can be found in:
Jul 27 22:34:53 ip-172-31-42-207 web: npm ERR!     /home/webapp/.npm/_logs/2021-07-27T22_34_53_315Z-debug.log
Jul 27 22:34:53 ip-172-31-42-207 web: > ballotbox-server@0.0.1 start /var/app/current
Jul 27 22:34:53 ip-172-31-42-207 web: > tsc && node build/index.js

It seems TS is unable to generate my JS files due to permissions. I didn't have this problem in my old environment. Also I've already added the unsafe-perm=true to .npmrc.

Any thoughts are greatly appreciated,

Thanks!

AliT
  • 11
  • 1
  • 2

1 Answers1

0

It seems indeed to be a permission problem. EBS handles by default Javascript and not Typescript so it can be tricky to make it handle the tsc command. You have two solutions:

  • Transpile your code into JS before your upload on EBS. This means running tsc locally or using a CI pipeline like GitHub Actions or AWS CodeBuild
  • Use .ebextensions files to install typescript globally on the EC2 instances your EBS environment will manage, before the npm start is run by EBS. You can for instance write a bash script which will then install all the dependencies needed in order to run tsc. See here: https://stackoverflow.com/a/43511790/17043933