【问题标题】:Angular App Fails to Build using GitHub Actions ('Cannot find module')Angular 应用程序无法使用 GitHub 操作构建(“找不到模块”)
【发布时间】:2021-03-08 17:18:30
【问题描述】:

我能够在本地构建我的项目(使用我的 GitHub Action 使用的相同构建命令)。但是,在管道中运行时它会失败并出现以下错误(还有更多,但基本上都是相同的错误)。

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'.

它无法解析我正在导入到组件中的某些文件。它说“找不到模块”,但这些只是打字稿接口文件,它们不在模块中。我是 GitHub Actions 的新手,真的不知道如何开始调试此类问题。

这是我的 actions.yml 文件

# 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

npm 脚本build-prod 转换为ng build --prod。同样,此命令在本地成功,只是在 GitHub Actions 中不成功。

【问题讨论】:

    标签: angular typescript git github-actions


    【解决方案1】:

    这看起来很像这个问题的同一个问题:

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

    我刚刚遇到了和你一样的问题,这个问题为我解决了。

    【讨论】:

    • 哇,是的,这解决了我的问题。对于其他人......这是一个外壳问题。我有像import { NewUserRequest } from '../shared/models/view-models/NewUserRequest' 这样的导入语句,但文件本身被命名为newUserRequest.ts。更新这些导入语句解决了构建问题
    • 遇到了同样的问题。但是为什么我们需要改变它,因为它应该可以正常工作...... Github action真是太可惜了。
    猜你喜欢
    • 2015-01-18
    • 2019-12-30
    • 2020-12-06
    • 2019-01-01
    • 2021-11-03
    • 2021-03-17
    • 2019-10-13
    • 2019-01-28
    • 2018-01-06
    相关资源
    最近更新 更多