CodeBuild 中的 NextJS 独立导出构建规范错误“找不到模块:无法解析组件”

问题描述 投票:0回答:1

我通过 CodePipeline/CodeBuild 运行以下构建规范

version: 0.2

phases:
    install:
        runtime-versions:
            nodejs: 18
    pre_build:
        commands:
            - echo Installing source NPM dependencies...
            - cd webConsole
            - npm install -g yarn
            - yarn install
    build:
        commands:
            - echo Build started on $(date)
            - yarn build
    post_build:
        commands:
            - aws s3 cp --recursive --acl public-read ./out s3://<S3_BUCKET>
            - aws s3 cp --acl public-read --cache-control="max-age=0, no-cache, no-store, must-revalidate" ./out/index.html s3://<S3_BUCKET
            - aws cloudfront create-invalidation --distribution-id <CLOUDFRONT DISTRO> --paths /*
artifacts:
    baseDirectory: build
    files:
        - "**/*"
cache:
    paths:
        - node_modules/**/*

我在本地运行相同的步骤,并且在相同版本的节点上运行良好。我想知道是否有人在管道的 CodeBuild 阶段看到过同样的事情。安装工作正常,但我在构建阶段遇到以下错误

./src/components/Login.jsx
Module not found: Can't resolve './misc/CustomCheckbox'

https://nextjs.org/docs/messages/module-not-found

我已检查我的导入是否使用了正确的大小写,并且 CustomCheckbox 只是一个样式化的 MUI 复选框。,

nextjs 构建是一个独立构建,具有以下配置

/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
    output: "export",
    trailingSlash: true,
    optimizeFonts: false,
};

module.exports = nextConfig;
next.js yarnpkg aws-codepipeline codebuild
1个回答
0
投票

解决方案

  1. 再次克隆存储库,
  2. 比较两个存储库中文件夹/文件名的大小写

对于文件:

  • 使用
    git mv filename to Filename

对于文件夹:

  • 将文件夹完全重命名为另一个名称
  • git 提交更改
  • 将文件夹重命名为你想要的名称
  • git 提交更改

描述

我也有同样的。我可以毫无问题地在本地运行构建, 但在 github 中我遇到了“模块未找到错误”。我与同一技术堆栈上的其他 2 个项目进行了比较,它们构建得很好。

所以事实证明,如果

git
发生了更改,
case
不会跟踪文件夹/文件的更改。就我而言,我将
Components
文件夹重命名为
components
文件夹,但未对其进行跟踪。

其他答案

NodeJS 的 Github 操作 - 本地文件的“错误:找不到模块”

GitHub CI/Actions - 找不到模块。确保已安装此软件包

© www.soinside.com 2019 - 2024. All rights reserved.