Skip to content

Cannot read properties of undefined (reading 'removeAvailableModules') when using Rspack in dev mode #31268

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

Open
1 of 4 tasks
CuriousSyrup opened this issue May 19, 2025 · 2 comments · May be fixed by #31337
Open
1 of 4 tasks
Assignees
Labels
priority: medium Medium Priority (not high, not low priority) scope: bundlers Issues related to webpack, rollup type: bug

Comments

@CuriousSyrup
Copy link

CuriousSyrup commented May 19, 2025

Current Behavior

Running nx build <project> --configuration=development with @nx/rspack causes this error:

TypeError: Cannot read properties of undefined (reading 'removeAvailableModules')

Expected Behavior

The development build should succeed using Rspack with default settings, even if the "optimization" field is omitted from the dev config.

GitHub Repo

https://github.com/CuriousSyrup/nx-rspack-dev-bug

Steps to Reproduce

  1. Create workspace
    npx create-nx-workspace nx-node-lib-rspack
    cd nx-node-lib-rspack

  2. Add node + rspack plugins
    npx nx add @nx/node
    npx nx g @nx/node:lib libs/node-lib --useProjectJson
    npx nx add @nx/rspack

  3. Create libs/node-lib/rspack.config.js with:

const { join } = require('path');
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');

module.exports = {
  entry: './src/index.ts',
  output: {
    path: join(__dirname, 'dist'),
  },
  plugins: [
    new NxAppRspackPlugin({
      target: 'node',
      tsConfig: './tsconfig.lib.json',
      main: './src/index.ts',
      progress: true,
    }),
  ],
};
  1. In libs/node-lib/project.json, set configurations:
{
  "build": {
    "executor": "@nx/rspack:rspack",
    "options": {
      "main": "libs/node-lib/src/index.ts",
      "rspackConfig": "libs/node-lib/rspack.config.js",
      "outputPath": "dist"
    },
    "defaultConfiguration": "production",
    "configurations": {
      "development": {
        "mode": "development"
      },
      "production": {
        "mode": "production",
        "optimization": true,
        "sourceMap": false
      }
    }
  }
}
  1. Run builds
    nx build node-lib --configuration=production # ✅ works
    nx build node-lib --configuration=development # ❌ crashes

Nx Report

Node           : 22.14.0
OS             : linux-x64
Native Target  : x86_64-linux
npm            : 10.9.2

nx                     : 21.0.3
@nx/js                 : 21.0.3
@nx/jest               : 21.0.3
@nx/eslint             : 21.0.3
@nx/workspace          : 21.0.3
@nx/devkit             : 21.0.3
@nx/module-federation  : 21.0.3
@nx/node               : 21.0.3
@nx/rspack             : 21.0.3
@nx/web                : 21.0.3
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/rspack/plugin
---------------------------------------
Cache Usage: 0.00 B / 182.38 GB

Failure Logs

> nx run @nx-test/node-lib:build:development


 NX   Cannot read properties of undefined (reading 'removeAvailableModules')

Package Manager Version

No response

Operating System

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

Additional Information

No response

@Milananas
Copy link

Milananas commented May 21, 2025

I can confirm this issue still exists on NX 21.1.1

@konqi
Copy link

konqi commented May 22, 2025

I'm having the same issue.
I think this is caused by this line, as it cancels out anything you set in the rspack.config under optimization by overriding it with undefined when it should use config.optimization before defaulting to... something? 🤷🏻 . Not sure how to verify my theory though.

konqi added a commit to konqi/nx that referenced this issue May 26, 2025
@FrozenPandaz FrozenPandaz added priority: medium Medium Priority (not high, not low priority) scope: bundlers Issues related to webpack, rollup labels May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium Medium Priority (not high, not low priority) scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants