Skip to content

Nx Webpack plugin - builds fail in Docker environment when importing monorepo libraries #30098

Open
@tdaudelin

Description

Current Behavior

From my example repo, when running locally on MacOS, a basic build command like nx build api succeeds without issue. When running the same command from within a Dockerfile to produce a container image, the build fails because Webpack is unable to resolve a library module that lives in the same monorepo.

Expected Behavior

Build commands should be consistent when utilizing the same versions of Node, NPM, and Nx - regardless of if they are run from within a Docker image or locally.

GitHub Repo

https://github.com/tdaudelin/nx-issue-repro

Steps to Reproduce

  1. Please see the readme in the provided GitHub repo. All Nx generator commands used to create the files in that repo can be found in the details of each commit message.

Nx Report

(This is the report generated from inside the Alpine Linux Docker image, where the issue appears)

Node           : 22.11.0
OS             : linux-arm64
Native Target  : aarch64-linux
npm            : 10.9.0

nx                 : 20.4.4
@nx/js             : 20.4.4
@nx/jest           : 20.4.4
@nx/eslint         : 20.4.4
@nx/workspace      : 20.4.4
@nx/devkit         : 20.4.4
@nx/eslint-plugin  : 20.4.4
@nx/express        : 20.4.4
@nx/node           : 20.4.4
@nx/vite           : 20.4.4
@nx/web            : 20.4.4
@nx/webpack        : 20.4.4
typescript         : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/webpack/plugin
@nx/eslint/plugin
@nx/vite/plugin

Failure Logs

#12 2.916 > nx run api:build
#12 2.916 
#12 2.916 > webpack-cli build --node-env=production
#12 2.916 
#12 3.929 chunk (runtime: main) main.js (main) 2.43 KiB [entry] [rendered]
#12 3.929 
#12 3.929 ERROR in ./src/models.ts 6:33-63
#12 3.929 Module not found: Error: Can't resolve '@nx-issue-repro/dto' in '/tmp/apps/api/src'
#12 3.929 
#12 3.929 webpack compiled with 1 error (3ba49579bac00305)
#12 3.953 Warning: command "webpack-cli build --node-env=production" exited with non-zero status code
#12 3.954 
#12 3.954 
#12 3.954  NX   Running target build for project api and 1 task it depends on failed

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Hello! I am experiencing a build error while using the Nx Webpack plugin that only surfaces from within a Docker environment. The same build command succeeds if used locally. I have provided an example repository that reproduces this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions