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

npm aliases are ignored by nx sync and nx release #30159

Open
1 of 4 tasks
electrocnic opened this issue Feb 24, 2025 · 0 comments
Open
1 of 4 tasks

npm aliases are ignored by nx sync and nx release #30159

electrocnic opened this issue Feb 24, 2025 · 0 comments

Comments

@electrocnic
Copy link

electrocnic commented Feb 24, 2025

Current Behavior

Not sure if this is a feature-request or a bug report, but anyways:

libA/package.json:

{
  "name": "@scope-source/libA",
  "version": "0.0.1",
  "type": "module",
  "main": "./src/index.ts",
  "types": "./src/index.ts",
  "exports": {
    ".": {
      "types": "./src/index.ts",
      "import": "./src/index.ts",
      "default": "./src/index.ts"
    },
    "./package.json": "./package.json"
  },
  "dependencies": {
    "@scope/libB": "npm:@scope-source/[email protected]",
    "@scope/libC": "npm:@scope-source/[email protected]",
    "@scope/libD": "npm:@scope-source/[email protected]"
  }
}

(All other libs, libB, libC, libD have exactly the same package.json structure and naming scheme with the npm scopes and aliases and so on).

This is my current setup throughout the nx workspace: Every project/lib contains dependencies with npm aliases, in order to allow myself to easily switch my dependencies between local source code project reference and remote artifact registry pulling, where I simply switch the @scope-source to @scope-published and therefore handle several issues with how npm deals with these local references in the case I want to test my build with prebuilt published artifacts instead.
I do not need to adapt each and every import statement in my typescript code for example, I can leave them all with import { ... } from '@scope/package-name', they do not need to "know" whether the package is a local source or a external published bundle.

Now if I run npx nx sync for the first time after I changed my dependencies to use aliases, all the project references in the tsconfig files would get removed.

nx release is also broken when npm aliases are used.
it calls npm i --package-lock-only which would no longer find the locally referenced sources from the aliases as the aliases are not bumped by nx release while the package versions are indeed bumped.

Expected Behavior

This is not what I hoped for. I think nx should resolve npm aliases too.

GitHub Repo

No response

Steps to Reproduce

  1. One lib (libA) with a package.json and a npm lib name containing "@some-scope-source/libA",

  2. "dependencies": {"@some-scope/libB": "npm:@some-scope-source/[email protected]"}

  3. and possibly also a ts or js source file which imports stuff from libB via import { someFunc } from '@some-scope/libB' (this uses the alias, so the real source of the package can change in the package.json without affecting this import statement).

  4. add libB also with a package.json and lib name containing "@some-scope-source/libB"

  5. the whole nx workspace should be configured as a project-references thingy.

  6. run npx nx sync. Observed output: nothing, there will not be any tsconfig references in libA/tsconfig.lib.json or libA/tsconfig.json, but they should there as expected.

Expected:
libA/tsconfig.json:

"references": [
  {
     "path": "../libB"
  },
]

libA/tsconfig.lib.json:

"references": [
  {
     "path": "../libB/tsconfig.lib.json"
  },
]

Nx Report

Node           : 22.13.1
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 11.1.0

nx                     : 20.4.4
@nx/js                 : 20.4.4
@nx/jest               : 20.4.4
@nx/eslint             : 20.4.4
@nx/workspace          : 20.4.4
@nx/devkit             : 20.4.4
@nx/eslint-plugin      : 20.4.4
@nx/module-federation  : 20.4.4
@nx/plugin             : 20.4.4
@nx/react              : 20.4.4
@nx/vite               : 20.4.4
@nx/web                : 20.4.4
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/js/typescript
@nx-dotnet/core
---------------------------------------
Community plugins:
@nx-dotnet/core : 2.5.0
---------------------------------------
Local workspace plugins:
         @hg/certificate-helper
         @hg/release-helper

Failure Logs

Package Manager Version

No response

Operating System

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

Additional Information

If I add the non-aliased source dependency in addition to the alias, even tho the typescript source never directly imports from '@scope-source/package-name' but only ever from the alias '@scope/package-name', then nx sync will still generate the expected tsconfig path references, which I will use as a workaround for now:

"dependencies": {
  "@scope-source/libB": "0.0.1",
  "@scope/libB": "npm:@scope-source/[email protected]",
  "@scope-source/libC": "0.0.1",
  "@scope/libC": "npm:@scope-source/[email protected]",
  "@scope-source/libD": "0.0.1",
  "@scope/libD": "npm:@scope-source/[email protected]"
}
@electrocnic electrocnic changed the title npm aliases are ignored by nx sync npm aliases are ignored by nx sync and nx release Feb 25, 2025
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