Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@nx/rspack - Cannot set custom port option to 'serve' executor #383

Open
x77t opened this issue Mar 7, 2024 · 0 comments
Open

@nx/rspack - Cannot set custom port option to 'serve' executor #383

x77t opened this issue Mar 7, 2024 · 0 comments

Comments

@x77t
Copy link

x77t commented Mar 7, 2024

The Problem

The nx/rspack withNx method does not pick the custom port option that comes from the project.json or the CLI args and instead just uses a hardcoded value of 4200 when the serve command is being executed.

Problem Reference

Problem Example

nx deps:

"devDependencies": {
    "@nx/react": "18.0.5",
    "@nx/rspack": "^18.0.2",
}

project configs:

// project.json

{
  "name": "crm-root",
  "$schema": "../../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/crm/root/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nx/rspack:rspack",
      "outputs": [
        "{options.outputPath}"
      ],
      "defaultConfiguration": "production",
      "options": {
        "target": "web",
        "outputPath": "dist/apps/crm/root",
        "main": "apps/crm/root/src/main.ts",
        "tsConfig": "apps/crm/root/tsconfig.app.json",
        "rspackConfig": "apps/crm/root/rspack.config.js",
        "assets": [
          "apps/crm/root/src/favicon.ico",
          "apps/crm/root/src/assets"
        ]
      },
      "configurations": {
        "development": {
          "mode": "development"
        },
        "production": {
          "mode": "production",
          "optimization": true,
          "sourceMap": false
        }
      }
    },
    "serve": {
      "executor": "@nx/rspack:dev-server",
      "options": {
        "buildTarget": "crm-root:build:development"
      },
      "configurations": {
        "development": {},
        "production": {
          "buildTarget": "crm-root:build:production"
        }
      }
    },
    "serve-static": {
      "executor": "@nx/web:file-server",
      "defaultConfiguration": "production",
      "options": {
        "buildTarget": "crm-root:build",
        "watch": false,
        "port": 4444
      },
      "configurations": {
        "development": {
          "buildTarget": "crm-root:build:development"
        },
        "production": {
          "buildTarget": "crm-root:build:production"
        }
      }
    }
  },
  "tags": []
}
// rspack.config.js

const { composePlugins, withNx, withReact } = require('@nx/rspack')
const rspack = require("@rspack/core")

module.exports = composePlugins(withNx(), withReact(), (config) => {
  return {
    ...config,
    context: __dirname,
    node: {
      __dirname: true
    },
    module: {
      ...config.module,
      rules: [
        ...(config.module.rules || []),
        {
          test: /\.css$/,
          use: ["postcss-loader"],
          type: "css",
        },
      ]
    },
    plugins: [
      ...config.plugins,
      new rspack.container.ModuleFederationPlugin({
        name: 'crm-root',
        remotes: [],
      }),
    ]
  };
});

outputs:

nx run crm-root:serve

You are depending on apply entry lazily, this behavior has been deprecated, you can setup 'experiments.rspackFuture.disableApplyEntryLazily = true' to disable this behavior, and this will be enabled by default in v0.5
    Set env `RSPACK_DEP_WARNINGS` to 'false' to temporarily disable deprecation warnings.

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:4200/
<i> [webpack-dev-server] On Your Network (IPv4): http://192.168.114.2:4200/
<i> [webpack-dev-server] On Your Network (IPv6): http://[fe80::1]:4200/
<i> [webpack-dev-server] Content not from webpack is served from '<my_project_path>/public' directory

...
nx run crm-root:serve --port=4444

You are depending on apply entry lazily, this behavior has been deprecated, you can setup 'experiments.rspackFuture.disableApplyEntryLazily = true' to disable this behavior, and this will be enabled by default in v0.5
    Set env `RSPACK_DEP_WARNINGS` to 'false' to temporarily disable deprecation warnings.

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:4200/
<i> [webpack-dev-server] On Your Network (IPv4): http://192.168.114.2:4200/
<i> [webpack-dev-server] On Your Network (IPv6): http://[fe80::1]:4200/
<i> [webpack-dev-server] Content not from webpack is served from '<my_project_path>/public' directory

How To Reproduce

  • Create a simple react app with rspack using nx/react and nx/rspack plugins
  • Try passing a custom port value and serving the app from nx CLI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant