FrenchMajesty
FrenchMajesty

Reputation: 1159

Cannot build Typescript app on Bitbucket Pipeline

I have an issue trying to get my TS app to compile in a Bitbucket Pipeline.

Here's my .yaml file:

image: node:10.16.3

pipelines:
  pull-requests:
    '**':
      - step:
          name: Install dependencies
          caches:
            - node
          script:
            - npm install -g typescript
            - npm install
      - parallel:
        - step:
            name: Build App
            caches:
              - node
            size: 2x
            script:
              - node -v && npm -v && tsc -v
              - npm run build
        - step:
            name: Run Tests
            caches:
              - node
            script:
              - echo "Run tests"

However it fails with the following error:

bash: tsc: command not found

I've spend a long time Googling around to try to find the answer but I have had no luck getting past this issue. I tried and failed to overcome a few months ago, and today I looped back around to give it a shot but still no success.

Any help is duly appreciated. Thank you for your support

Upvotes: 0

Views: 2825

Answers (2)

hoadng
hoadng

Reputation: 11

You have tsc: command not found error because you install typescript in the first step, not the second step where you actually use it. Bitbucket pipelines don't automatically pass the environment to the next step. You can either:

  • Provide artifact: node_modules option in the first step. In which case, Bitbucket Pipelines will pass the whole node_modules folder to the next step.
  • Just simply do npm install directly in the step that needs it so you don't need to pass the node_modules around.

Another tip:

  • You should use npm ci for CI pipelines to prevent unexpected package updates.

Upvotes: 1

kdau
kdau

Reputation: 2099

Based on your question and comment, there are two separate issues here:

  1. The top-level pipeline script can't find tsc, probably because its environment wasn't updated after the typescript package was installed. I would suggest just leaving out the - node -v && npm -v && tsc -v line permanently (or at least its && tsc -v part), since any of those being missing would quickly show up when you try to - npm run build anyway.
  2. Your pipeline is running out of memory. size: 2x for 8GB appears to be the most you can request right now, so you'll have to look at your build script for ways to reduce the memory footprint. Some ideas:
    • You're already asking for the latest version of TypeScript in your install step (which itself might be worrisome; consider future breaking changes), but you're using Node.js 10. I don't know if Node.js 14 would have a lower footprint, but it's worth a try.
    • Make sure your build script isn't itself running anything in parallel. (The parallel step in your pipeline config doesn't count, as that's using a separate VM.)
    • Check the options of the tools your build script calls for optimizations you can turn on.
    • At worst, you might have to split your project's build somehow into pieces that fit within Bitbucket limits.

Upvotes: 2

Related Questions