Niharika Chauhan

Niharika Chauhan started this conversation 9 months ago.

0

1

aws

Why does my Next.js build fail in GitHub Actions with the error "Module not found: Can't resolve 'pdf-lib' and '@pdf-lib/fontkit'"?

Why is my Next.js build failing in GitHub Actions with the error: "Module not found: Can't resolve 'pdf-lib' and '@pdf-lib/fontkit'"? Specifically, the application works locally without any issues, but during the CI/CD pipeline in GitHub Actions, the build process cannot find these dependencies. What could be causing this discrepancy, and how can I resolve it to ensure a successful build in GitHub Actions?

codecool

Posted 9 months ago

The issue you're encountering with your Next.jsbuild failing in GitHub Actions with the error "Module not found: Can't resolve 'pdf-lib' and '@pdf-lib/fontkit'" could be due to several reasons:

Dependency Installation: Ensure that pdf-lib and @pdf-lib/fontkit are correctly installed in your project. Sometimes, dependencies might not be installed properly in CI/CD environments.

Case Sensitivity: GitHub Actions might be running on a case-sensitive file system, while your local environment is not. Double-check the casing of your import statements and file paths.

Node Modules Cache: Clear the node_modules folder and reinstall the dependencies. Sometimes, cached files can cause issues during the build process.

Configuration Differences: Verify that your package.json and package-lock.json files are consistent between your local environment and the GitHub Actions environment. Any discrepancies can lead to build failures.

Environment Variables: Check if there are any environment variables that might be affecting the build process differently in GitHub Actions compared to your local setup.

Webpack Configuration: Ensure that your Webpack configuration is correctly set up to handle these dependencies. You might need to adjust the configuration to properly resolve these modules.

Path Aliases: If you're using path aliases, make sure they are correctly configured in your next.config.js or tsconfig.json files.