I am facing an issue where my Docker build succeeds locally but fails when run in a GitHub Actions workflow. The failure is specifically occurring during the build step with a module resolution error.
Error Message:
#15 [build 6/6] RUN yarn build
#15 0.372 yarn run v1.22.19
#15 0.405 $ craco build
#15 2.204 Creating an optimized production build...
#15 9.174 Failed to compile.
#15 9.174
#15 9.175 Module not found: Error: Can't resolve '@/utils/actions/api/my-axios' in '/app/src/store'
#15 9.175
#15 9.175
#15 9.221 error Command failed with exit code 1.
#15 9.221 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
#15 ERROR: process "/bin/sh -c yarn build" did not complete successfully: exit code: 1
This error suggests that there's a problem with resolving the alias @ in the GitHub Actions environment, despite it working fine locally.
craco.config.js:
require("dotenv").config();
const path = require("path");
const webpack = require("webpack");
module.exports = {
webpack: {
configure: {
resolve: {
fallback: {
process: require.resolve("process/browser"),
zlib: require.resolve("browserify-zlib"),
stream: require.resolve("stream-browserify"),
util: require.resolve("util"),
buffer: require.resolve("buffer"),
asset: require.resolve("assert"),
},
},
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
process: "process/browser",
}),
],
alias: {
"@": path.resolve(__dirname, "src"),
},
},
};
Dockerfile:
# Use the official Node.js runtime as the base image
FROM node:19.9.0-alpine as build
# Set the working directory in the container
WORKDIR /app
# Copy package.json and package-lock.json (or yarn.lock, if you are using Yarn) to the container
COPY package.json yarn.lock ./
# Install project dependencies
# If you are using npm, replace with `RUN npm install`
RUN yarn install
# Copy the rest of the application code to the container
COPY . .
# Compile TypeScript to JavaScript
RUN yarn build
# Use Nginx as the production server
FROM nginx:alpine
# Copy the built React app to Nginx's web server directory
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY --from=build /app/build /usr/share/nginx/html
package.json:
{
....
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "craco eject"
},
}