5

I'm able to build my project locally (using the same build command that my GitHub Action uses). However, it fails when running in the pipeline with the below errors (there are more, but all basically the same error).

ERROR in src/app/root-store/actions.ts:3:32 - error TS2307: Cannot find module '../shared/models/view-models/NewUserRequest'.

3 import { NewUserRequest } from '../shared/models/view-models/NewUserRequest';
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app/root-store/frame-store/actions.ts:3:41 - error TS2307: Cannot find module 'src/app/shared/models/requests/FrameRequests'.

3 import { CreateFrameImageRequest } from 'src/app/shared/models/requests/FrameRequests';
                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app/shared/models/translators/frameTranslator.ts:4:61 - error TS2307: Cannot find module '../requests/FrameRequests'.

It cannot resolve some files I'm importing into components. It says "cannot find module" yet these are just typescript interface files, they are not in modules. I'm new to GitHub Actions & really don't know how to begin debugging this type of problem.

Here is my actions.yml file

# This is a basic workflow to help you get started with Actions

name: Build

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]
  # pull_request:
  #   branches: [ master ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    name: Build
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout Repo
        uses: actions/checkout@v2
        with:
          ref: master

      - name: Setup Node
        uses: actions/setup-node@v2-beta
        with:
          node-version: '10'

      - name: Cache node modules
        uses: actions/cache@v2
        env:
          cache-name: cache-node-modules
        with:
          # npm cache files are stored in `~/.npm` on Linux/macOS
          path: ~/.npm
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

      - name: Install Dependencies
        run: npm install

      - name: Build Project
        run: npm run build-prod

The npm script build-prod translates to ng build --prod. Again, this command is successful locally, just not in GitHub Actions.

Avery Ferrante
  • 132
  • 1
  • 6

1 Answers1

6

This looks awefully like the same problem from this question:

Github Actions for NodeJS - 'Error: Cannot find module' for local file

I just had the same problem as yours and this question solved it for me.

Jim Jimson
  • 2,368
  • 3
  • 17
  • 40
  • 2
    Wow, yes that solved my issue. For everyone else....it was a casing issue. I had import statements like `import { NewUserRequest } from '../shared/models/view-models/NewUserRequest'` but the file itsself is named `newUserRequest.ts`. Updating these import statements solved the build issue – Avery Ferrante May 01 '21 at 22:06
  • Encountered the same issue. But why do we need to change it since it should work properly... What a shame with Github action. – kitta Dec 18 '21 at 08:19
  • 2
    To prevent these errors in the future, you can turn on `forceConsistentCasingInFileNames` in your tsconfig: https://stackoverflow.com/questions/51197940/file-name-differs-from-already-included-file-name-only-in-casing-on-relative-p – frodo2975 Mar 02 '22 at 21:24
  • 1
    thank you good sir. been scratching my head on this for over 2 hours. – iamkenos May 07 '22 at 08:00