Question

App Platoform when add enviroment variables I have yarn command errors

Hi, how are you?

I am starting to test this service that is really very good and I am encountering quite strange behaviors;

When I generate the basic application with the commands to run the application it works perfectly for me, obviously the difference is that the application fails because I clearly need to add the environment variables. When I add the environment variables the commands in the compilation step stop working for me.

This would be the YAML that the commands work.

alerts:
- disabled: true
  rule: DEPLOYMENT_FAILED
- rule: DOMAIN_FAILED
name: test-app
region: nyc
services:
- build_command: | -
    npm install pm2 -g
    yarn pre-build
    yarn tsc
  environment_slug: node-js
  github:
    branch: master
    deploy_on_push: true
    repo: dg / test-app
  http_port: 8080
  instance_count: 1
  instance_size_slug: basic-xs
  name: test-app
  routes:
  - path: /
  run_command: pm2-runtime start ecosystem.config.js
  source_dir: /

This would be the result.

Running custom build command: npm install pm2 -g
 yarn pre-build
 yarn tsc
 npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random () in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
 / layers / heroku_nodejs-engine / nodejs / bin / pm2-runtime -> / layers / heroku_nodejs-engine / nodejs / lib / node_modules / pm2 / bin / pm2-runtime
 / layers / heroku_nodejs-engine / nodejs / bin / pm2 -> / layers / heroku_nodejs-engine / nodejs / lib / node_modules / pm2 / bin / pm2
 / layers / heroku_nodejs-engine / nodejs / bin / pm2-dev -> / layers / heroku_nodejs-engine / nodejs / lib / node_modules / pm2 / bin / pm2-dev
 / layers / heroku_nodejs-engine / nodejs / bin / pm2-docker -> / layers / heroku_nodejs-engine / nodejs / lib / node_modules / pm2 / bin / pm2-docker
 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules / pm2 / node_modules / chokidar / node_modules / fsevents):
 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os": "darwin", "arch": "any"} (current: {"os": "linux", "arch": "x64"})
 
 + pm2@5.1.2
 added 181 packages from 200 contributors in 14.838s
 yarn run v1.22.17
 $ cpy --cwd = src --parents '** / *' '! ** / *. ts' ../dist/src
 Donate in 1.04s.
 yarn run v1.22.17
 $ tsc
 Done in 10.19s.

This result makes all the sense since it works well, except that when the application is executed it asks me for the environment variables (obvious thing).

Now when I add the environment variables even just one for testing it throws me this error.

+ pm2@5.1.2
added 181 packages from 200 contributors in 15.583s
yarn run v1.22.17
$ cpy --cwd = src --parents '** / *' '! ** / *. ts' ../dist/src
/ bin / sh: 1: cpy: not found
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 127.
yarn run v1.22.17
$ tsc
/ bin / sh: 1: tsc: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
building: exit status 127
ERROR: failed to build: exit status 1

This would be the yaml for the latter case.

alerts:
- disabled: true
  rule: DEPLOYMENT_FAILED
- rule: DOMAIN_FAILED
name: test-app
region: nyc
services:
- build_command: | -
    npm install pm2 -g
    yarn pre-build
    yarn tsc
  environment_slug: node-js
  envs:
  - key: NODE_ENV
    scope: RUN_AND_BUILD_TIME
    value: production
  github:
    branch: master
    deploy_on_push: true
    repo: dg / test-app
  http_port: 8080
  instance_count: 1
  instance_size_slug: basic-xs
  name: test-app
  routes:
  - path: /
  run_command: pm2-runtime start ecosystem.config.js
  source_dir: /

In summary if I add environment variables it stops working for me.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @gustavogarcete,

It seems like with NODE_ENV=production Yarn will skip installing some packages that are actually required for the build, usually those configured as devDependencies.

What you can do is set the NODE_ENV variable only at run-time, like so:

...
services:
- ...
  envs:
  - key: NODE_ENV
    scope: RUN_TIME
    value: production
  ...

This way the build will continue as usual and your app will run with NODE_ENV set to production.