I have been deploying a node.js server application via app platform without issue. In the last push to github, I have introduced typescript which has made significant changes to my package.json and package-lock.json including adding typescript 4.1.3.

my build command is now

"build": "tsc",

But my build is failing because with the following because it can’t find the tsc command. relevant bit of the deployment logs below..

tsystems-server | 16:28:37 Installing node_modules using npm
tsystems-server | 16:28:44 added 119 packages in 5.537s
tsystems-server | 16:28:45 Running custom build command: npm run build
tsystems-server | 16:28:45 
tsystems-server | 16:28:45 > tsystems-server@1.0.0 build /workspace
tsystems-server | 16:28:45 > tsc
tsystems-server | 16:28:45 
tsystems-server | 16:28:45 sh: 1: tsc: not found

Not sure what is going wrong, the npm run build command works locally. I have tried manually referencing “./node_modules/....etc../tsc” in the build command but that didn’t work. Also tried npx tsc but that just got really wierd.

Any clues?

Michael

1 comment
  • Ok this is getting ridiculous now, this is now my build command in package.json…

    "build": "rm -rf node_modules & npm install --force && npm list -depth 0 && tsc"
    

    but the build process still won’t make the new packages (including typescript) available in the npm environment when the tsc command is run.

    Am I missing something? Seems to be broken to me.

    This is the relevant bit of the build logs…

    tsystems-server | 09:00:30 > tsystems-server@1.0.0 build /workspace
    tsystems-server | 09:00:30 > rm -rf node_modules & npm install --force && npm list -depth 0 && tsc
    tsystems-server | 09:00:30 
    tsystems-server | 09:00:31 npm WARN using --force I sure hope you know what you are doing.
    tsystems-server | 09:00:37 added 119 packages from 75 contributors and audited 379 packages in 5.67s
    tsystems-server | 09:00:37 found 0 vulnerabilities
    tsystems-server | 09:00:37 
    tsystems-server | 09:00:38 tsystems-server@1.0.0 /workspace
    tsystems-server | 09:00:38 +-- cookie-session@1.4.0
    tsystems-server | 09:00:38 +-- cors@2.8.5
    tsystems-server | 09:00:38 +-- dotenv@8.2.0
    tsystems-server | 09:00:38 +-- express@4.17.1
    tsystems-server | 09:00:38 +-- googleapis@66.0.0
    tsystems-server | 09:00:38 +-- passport@0.4.1
    tsystems-server | 09:00:38 +-- passport-google-oauth20@2.0.0
    tsystems-server | 09:00:38 `-- pg@8.5.1
    tsystems-server | 09:00:38 
    tsystems-server | 09:00:38 sh: 1: tsc: not found
    

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.

×
3 answers

This is a known issue with App Platform node builds NOT installing dev dependencies (which is really stoopid).

to fix, alter your build command to this.

npm install --only=dev && npm run build && npm prune --production

The issue is discussed here…

https://www.digitalocean.com/community/questions/how-do-you-use-node-js-devdependencies-in-the-app-platform-builds

  • I just tried that and got

    Your build job failed because it was terminated. This often happens due to resource exhaustion.
    Error code: BuildJobTerminated
    
    • Interesting. Clearly looks like a performance issue, not a functional issue. maybe you have a lot of dev dependencies? sometimes installing stuff with npm can trigger make commands and maybe that whole install process is taking too long, or using too much memory.

      perhaps instead of npm install –only-dev, you could npm install only those dependencies you need for the build? e.g. typescript.

I have basically followed the community guidelines here… https://www.digitalocean.com/community/tutorials/setting-up-a-node-project-with-typescript

by Jordan Irabor
Writing server-side JavaScript can be challenging as a codebase grows. TypeScript is a typed (optional) super-set of JavaScript that can help with building and managing large-scale JavaScript projects. It can be thought of as JavaScript with additional features like strong static typing, compilation and object oriented programming. This tutorial will explore how to use the [Express](https://expressjs.com/) framework with TypeScript.

Hello,

I understand that you are experiencing an issue with compiling TypeScript while building the app. You need to call “tsc” from an npm script by including command such as ( npm install typescript -g ) because I can see the build is failing at below line with “tsc not found” error:

tsc -p ./server/tsconfig.json –outDir ./dist && next build

Can you try this and keep us posted, if this helped!

Cheers,
Sri Charan

  • Hi Sri, thanks for responding.

    Per the initial message, I am calling tsc from an npm script

    "build": "tsc"
    

    I disagree that I need to install typescript globally, the act of installing it locally (per my package.json file) should make tsc available via the package.json script and this is the case on my local machine.

    What I did try was adding an npm list to my build command as a debugging tool…

      "scripts": {
        "build": "npm list && tsc",
        "start": "node dist/index.js",
        "start:dev": "nodemon index.ts"
      },
    

    When I look at the output from npm list, there is no reference to typescript at all… which suggests to me that the app platform process is not refreshing my local npm modules correctly.

Submit an Answer