Skip to content

[Bug]: Using extensionAlias with non-exist package.json#module cause error #7665

@colinaaa

Description

@colinaaa

System Info

npmPackages:
@rspack/cli: 1.0.0-beta.5 => 1.0.0-beta.5
@rspack/core: 1.0.0-beta.5 => 1.0.0-beta.5

Details

When using resolve.extensionAlias, if one of the NPM package has a wrong package.json(e.g.: package.json#module set to a non exist path), Rspack failed to resolve the package without useful diagnostic message.

E.g.:

import { foo } from 'invalid-pkg'
{
    "name": "invalid-pkg",
    "main": "./exist.js",
    "module": "./non-exist.js"
}
// rspack.config.js
const config = {
  devtool: false,
  entry: {
    main: {
      import: "./src/index.js",
    },
  },
  resolve: {
    mainFields: ['module', 'main'],
    extensionAlias: {
      '.js': ['.ts', '.js']
    }
  },
  mode: "development",
}
export default config

While webapck and esbuild will fallback to package.json#main, Rspack failed to resolve with error:

ERROR in ./src/index.js 1:0-31
  × All of the aliased extension are not found


Rspack compiled with 1 error in 10 ms

Reproduce link

https://github.com/colinaaa/rspack-repro-resolve-extension-alias

Reproduce Steps

  1. pnpm install
  2. npm run build:rspack

The error will show up.

npm run build:webpack is fine.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingupstream

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions