nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.78k stars 2.37k forks source link

NX Cannot find configuration for task web:serve in Docker container #23420

Open Nazar-Brunarskyi opened 6 months ago

Nazar-Brunarskyi commented 6 months ago

Current Behavior

I want to Dockerize my next js app for this I have created a docker file:

FROM node:18.18.2-alpine

WORKDIR /usr/src/apps

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 4200

CMD ["npm", "run", "web:serve:qa"]

to build an image i use $ docker build -f Dockerfile.web -t web .command.

The Image is built successfully.

when I try to run a container from that image i get an error:

> npx nx run web:serve:qa
 NX   Cannot find configuration for task web:serve
Pass --verbose to see the stacktrace.

Expected Behavior

I expect the container to start successfully and I would be able to open the app inside browser

GitHub Repo

No response

Steps to Reproduce

  1. install the last nx 19
  2. create a next project
  3. add docker file
    
    FROM node:18.18.2-alpine

WORKDIR /usr/src/apps

COPY package*.json ./ RUN npm install

COPY . .

EXPOSE 4200

CMD ["npm", "run", "web:serve:qa"]

4. Use `$ docker build -f Dockerfile.web -t web . ` to build the image
5. run the container from that image

### Nx Report

```shell
report on my machine
Node   : 18.18.2
OS     : win32-x64
npm    : 9.8.1

nx                 : 19.0.2
@nx/js             : 19.0.2
@nx/jest           : 19.0.2
@nx/linter         : 19.0.2
@nx/eslint         : 19.0.2
@nx/workspace      : 19.0.2
@nx/devkit         : 19.0.2
@nx/eslint-plugin  : 19.0.2
@nx/nest           : 19.0.2
@nx/next           : 19.0.2
@nx/node           : 19.0.2
@nx/react          : 19.0.2
@nrwl/tao          : 19.0.2
@nx/web            : 19.0.2
@nx/webpack        : 19.0.2
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/next/plugin
@nx/jest/plugin
@nx/eslint/plugin
@nx/webpack/plugin

report inside docker container
Node   : 18.18.2
OS     : linux-x64
npm    : 9.8.1
nx                 : 19.0.2
@nx/js             : 19.0.2
@nx/jest           : 19.0.2
@nx/linter         : 19.0.2
@nx/eslint         : 19.0.2
@nx/workspace      : 19.0.2
@nx/devkit         : 19.0.2
@nx/eslint-plugin  : 19.0.2
@nx/nest           : 19.0.2
@nx/next           : 19.0.2
@nx/node           : 19.0.2
@nx/react          : 19.0.2
@nrwl/tao          : 19.0.2
@nx/web            : 19.0.2
@nx/webpack        : 19.0.2
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/next/plugin
@nx/jest/plugin
@nx/eslint/plugin
@nx/webpack/plugin

Failure Logs

> @project-name/source@0.0.0 web:serve:qa
> npx nx run web:serve:qa
 NX   Cannot find configuration for task web:serve
Pass --verbose to see the stacktrace.

Package Manager Version

9.8.1

Operating System

Additional Information

No response

Nazar-Brunarskyi commented 6 months ago

here is my project.json file

{
  "name": "web",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/web",
  "projectType": "application",
  "tags": ["scope:web"],
  "targets": {
    "build": {
      "executor": "@nx/next:build",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "outputPath": "dist/apps/web"
      },
      "configurations": {
        "development": {
          "outputPath": "apps/web"
        },
        "production": {},
        "qa": {}
      }
    },
    "serve": {
      "executor": "@nx/next:server",
      "defaultConfiguration": "development",
      "options": {
        "buildTarget": "apps/web:build",
        "dev": true,
        "port": 4200
      },
      "configurations": {
        "development": {
          "buildTarget": "web:build:development",
          "dev": true
        },
        "production": {
          "buildTarget": "web:build:production",
          "dev": false
        },
        "qa": {
          "buildTarget": "web:build:qa",
          "dev": false
        }
      }
    },
    "lint": {
      "executor": "@nx/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["apps/web/**/*.{ts,tsx,js,jsx}"]
      }
    }
  }
}
willdavidow commented 4 months ago

Not sure if you're still running into this problem, but I was just having the same issue. We spent a while debugging, and what fixed it in the end was adding thedist and .nx (cache) folders (in the monorepo root) to our .dockerignore file.

We also had to exclude the package-lock.json file from the Dockerfile but that could be some other issue in my environment not-specific to this. I haven't tried regenerating the package-lock.json file to see if that fixes it, we're just excluding it for now.

The hypothesis we've got on my team is that something in nx is crawling all the directories and stopping when it hits the dist and/or .nx folder(s) for some reason.