Skip to content

[Bug]: Modern Module Externals Configuration Issue #11663

@lzxb

Description

@lzxb

System Info

System:
OS: macOS 15.6.1
CPU: (10) arm64 Apple M4
Memory: 131.86 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.3.0 - ~/.nvm/versions/node/v24.3.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v24.3.0/bin/yarn
npm: 11.4.2 - ~/.nvm/versions/node/v24.3.0/bin/npm
pnpm: 10.9.0 - ~/.nvm/versions/node/v24.3.0/bin/pnpm
bun: 1.2.18 - ~/.bun/bin/bun
Browsers:
Chrome: 140.0.7339.133
Edge: 135.0.3179.98
Safari: 18.6
npmPackages:
@rspack/cli: ^1.5.3 => 1.5.3
@rspack/core: ^1.5.3 => 1.5.3

Details

Problem

When using Rspack with modern module output format combined with externals configuration, external dependencies fail to resolve correctly, resulting in undefined values.

Configuration

// rspack.config.ts
export default defineConfig({
  output: {
    module: true,
    library: {
      type: 'modern-module'
    }
  },
  externals: {
    'vue': 'module-import vue',
    'vue2': 'module-import vue2'
  }
});

Source Code

// src/index.ts
import { version } from './vue';
import { version as version2 } from './vue2';

console.log(version, version2); // Expected: "3.5.21 2.7.16", Actual: "undefined undefined"

Reproduction

pnpm build && node dist/main.mjs

Expected Output: 3.5.21 2.7.16
Actual Output: undefined undefined

Root Cause

The combination of:

  1. output.module: true + library.type: 'modern-module'
  2. externals with module-import syntax
  3. ES module imports

causes Rspack to generate incorrect import statements for external dependencies.

Impact

Affects library developers and projects using modern ES modules with external dependencies.

Reproduce link

https://github.com/lzxb/rspack-modern-module-error

Reproduce Steps

pnpm i && pnpm build && node dist/main.mjs

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions