我正在尝试使用 Github Actions 为我的 NextJS 应用程序设置 CI 工作流程。由于某种原因,我的
npm run build
命令如果 CI 工作流程失败,但它可以在本地运行。我收到错误./src/app/components/cards/Leetcode.js Module not found: Can't resolve '../../utils/useLeetcodeData'
。然而,该文件实际上确实存在于访问它的路径中。此外,该命令在我的本地计算机上运行并且不会抛出此错误。
这是我的.yml 文件
name: Deploy to Firebase
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
build:
name: Build and Deploy to Firebase
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/[email protected]
- name: Debug Information
run: |
ls -R # List all files in the repository
ls -R ./src # List files in the src directory
ls -R ./src/app/utils # List files in the utils directory
- name: Use Node.js 18
uses: actions/[email protected]
with:
node-version: 18
- name: Install Dependencies
run: npm ci
- name: Build
run: npm run build
- name: Deploy to Firebase
uses: w9jds/[email protected]
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
注意我已经添加了 调试信息 步骤来尝试验证文件的存在和路径,从输出中我可以看到它实际上是根据 .
./src/app/components/cards:
[... other files]
Leetcode.js <--- file that is importing the module
./src/app/utils:
[... other files]
useLeetCodeData.js <--- file with module
路径
src/app/component/cards/Leetcode
的 React 组件导入。进口线路是import useLeetCodeData from '../../utils/useLeetcodeData'
src/app/utils/useLeetCodeData.js
(再次强调,无论如何,这都是在本地工作的)什么可能导致此问题?
仔细检查 useLeetcodeData 中的“c”是否大写。在你的问题中,我看到你以两种方式提到它:
useLeetCodeData
和useLeetcodeData
。