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

js:swc generates invalid package.json when stripLeadingPaths is set #29761

Open
1 of 4 tasks
CynicalBusiness opened this issue Jan 27, 2025 · 0 comments
Open
1 of 4 tasks

Comments

@CynicalBusiness
Copy link

CynicalBusiness commented Jan 27, 2025

Current Behavior

When using stripLeadingPaths with the @nx/js:swc executor, the package.json generated by generatePackageJson (and subsequent generateExportsField) does not strip these paths like swc, resulting in an invalid package.json.

Example snippet from generated package:

{
  "exports": {
    "./package.json": "./package.json",
    ".": {
      "types": "./src/index.d.ts",
      "import": "./src/index.js",
      "default": "./src/index.js"
    }
  },
  "types": "./src/index.d.ts",
  "module": "./src/index.js",
  "type": "module",
  "main": "./src/index.js"
}

I've tried a few combinations of various swc and typescript settings (namely baseUrl), but it looks like the package json generation is handled one level up and not affected by, say, .swcrc.

Expected Behavior

When stripLeadingPaths is true, the package.json should look more like this:

{
  "exports": {
    "./package.json": "./package.json",
    ".": {
      "types": "./index.d.ts",
      "import": "./index.js",
      "default": "./index.js"
    }
  },
  "types": "./index.d.ts",
  "module": "./index.js",
  "type": "module",
  "main": "./index.js"
}

GitHub Repo

Appears in https://github.com/CynicalBusiness/yaqlib when set in either core's project.json or in nx.json.

Steps to Reproduce

  1. Setup Nx workspace and use the @nx/js:library generator to generate a buildable library with swc.
  2. Edit project.json (or nx.json) to set the option stripLeadingPaths to true
  3. Build.
  4. Observe that leading src path is indeed stripped but package json incorrectly reflects this.

Nx Report

Node           : 22.13.0
OS             : win32-x64
Native Target  : x86_64-windows
yarn           : 4.6.0

nx                 : 20.3.2
@nx/js             : 20.3.2
@nx/jest           : 20.3.2
@nx/eslint         : 20.3.2
@nx/workspace      : 20.3.2
@nx/devkit         : 20.3.2
@nx/eslint-plugin  : 20.3.2
@nx/web            : 20.3.2
typescript         : 5.6.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/jest/plugin
@nx/js/typescript

Failure Logs

Package Manager Version

Yarn v4.6.0

Operating System

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

Additional Information

The included report and package manager version are the same from both my repo and a fresh workspace + library (with swc+jest+eslint).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants