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

Use of extensionAlias fails resolution of subpath exports in exports fields #377

Closed
raviqqe opened this issue Apr 25, 2023 · 2 comments
Closed

Comments

@raviqqe
Copy link

raviqqe commented Apr 25, 2023

Problem

When the extensionAlias option is set to resolve TypeScript files (e.g. { ".js": [".ts", ".js"] },) enhanced-resolve tries to resolve subpath exports of external packages using the .ts file extension first and fails without trying the .js file extension.

Impact

This prevents the use of Webpack in projects that enables ES modules and TypeScript and uses external packages with subpath exports in their exports fields.

Error message

> npm run build

> webpack-exports-extension-alias@1.0.0 build
> webpack

assets by status 872 bytes [cached] 5 assets
./src/index.ts 43 bytes [built] [code generated]

ERROR in ./src/index.ts 1:0-42
Module not found: Error: Package path ./string.ts is not exported from package /Users/raviqqe/src/github.com/raviqqe/til/webpack-exports-extension-alias/node_modules/@raviqqe/hidash (see exports field in /Users/raviqqe/src/github.com/raviqqe/til/webpack-exports-extension-alias/node_modules/@raviqqe/hidash/package.json)

webpack 5.80.0 compiled with 1 error in 606 ms

package.json in an example external package:

{
  "name": "@raviqqe/hidash",
  "version": "1.4.7",
  "description": "Yet another extension to Lodash",
  "repository": "https://github.com/raviqqe/hidash",
  "type": "module",
  "typesVersions": {
    "*": {
      "*": [
        "dist/*"
      ]
    }
  },
  "exports": {
    "./*.js": {
      "types": "./dist/*.d.ts",
      "default": "./dist/*.js"
    },
    "./promise.js": {
      "types": "./dist/promise.d.ts",
      "default": "./dist/promise.js"
    },
    "./stream.js": {
      "types": "./dist/stream.d.ts",
      "default": "./dist/stream.js"
    },
    "./string.js": {
      "types": "./dist/string.d.ts",
      "default": "./dist/string.js"
    }
  },
  "scripts": {
    // ...
  },
  "devDependencies": {
    // ...
  }
}

Minimal reproducible example

Environment

  • enhanced-resolve: 5.13.0
  • webpack: 5.80.0
  • ts-loader: 9.4.2
  • Node.js: 20.0.0

Notes

Is this caused by the plugin order in the ResolverFactory?

@raviqqe raviqqe changed the title Use of extensionAlias fails resolution of subpath exports in exports fields in a package Use of extensionAlias fails resolution of subpath exports in exports fields Apr 25, 2023
@alexander-akait
Copy link
Member

Expected, exports should provide ts files, spec cleary says that everything that is not in exports should not be resolved

@alexander-akait
Copy link
Member

Duplicate of #355

@alexander-akait alexander-akait marked this as a duplicate of #355 Apr 25, 2023
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

2 participants