【问题标题】:GitHub CI/Actions - Cannot find module. Make sure this package is installedGitHub CI/Actions - 找不到模块。确保已安装此软件包
【发布时间】:2022-01-16 00:19:39
【问题描述】:

我想在我的 typescript react 应用程序中使用绝对导入路径。 因此,我将"baseUrl": "./src" 添加到tsconfig.json

我可以使用 yard build 在本地构建应用程序,但它不适用于 Github CI(操作)。

这是我从 CI 得到的错误

./src/components/App/App.tsx
Cannot find module: 'constants/Routes'. Make sure this package is installed.

我使用import { ROUTES } from 'constants/Routes' 导入组件。改用 ./constants/Routes 不适用于 set baseUrl。

我在使用.src baseUrl 时遇到了同样的错误。

tsconfig.json

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "module": "esnext",
    "target": "es5",
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react",
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    "baseUrl": "./src"
  },
  "include": ["src"]
}

Action.yml

name: Deploy

on:
  push:
    branches: [main, feature/*]
  pull_request:
    branches: [main]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout ????️
        uses: actions/checkout@v2.3.1

      - name: Install and Build ????
        run: |
          yarn --frozen-lockfile
          yarn build

      - name: Deploy ????
        uses: JamesIves/github-pages-deploy-action@4.1.5
        with:
          branch: gh-pages
          folder: build

【问题讨论】:

    标签: reactjs typescript github-pages github-actions


    【解决方案1】:

    在构建之前,您必须“npm install”安装所有包

    run: |
              npm install or yarn 
              yarn --frozen-lockfile
              yarn build
    
    

    【讨论】:

    • 这就是 yarn —frozen-lockfile 的作用……而且它无法找到我自己的文件,而不是一个包!
    猜你喜欢
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 2021-09-13
    • 2019-12-16
    • 2019-11-08
    • 2017-01-29
    • 1970-01-01
    相关资源
    最近更新 更多