nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.28k stars 2.32k forks source link

@nx/js 16.2.1 to 16.6.0 breaks #18520

Closed kodeine closed 11 months ago

kodeine commented 1 year ago

Current Behavior

[Nest] 19541 - 08/06/2023, 1:48:41 PM ERROR [ExceptionHandler] Account entity is missing @PrimaryKey() MetadataError: Account entity is missing @PrimaryKey()

Expected Behavior

no errors on serve/ compile

GitHub Repo

https://github.com/kodeine/NX/

Steps to Reproduce

1.clone github repo to reproduce you can try https://github.com/kodeine/NX/

  1. nx serve rspack-test

Note: it works fine on commit 4d69223 but on 5f4d4d9 it gives above error, rspack + nx were updated in last commit. updating @nx/js from 16.2.1 to 16.6.0 breaks it.

Nx Report

% nx report
>  NX  Falling back to ts-node for local typescript execution. This may be a little slower.
  - To fix this, ensure @swc-node/register and @swc/core have been installed

 >  NX   Report complete - copy this into the issue template

   Node   : 16.14.2
   OS     : darwin-arm64
   npm    : 8.5.0

   nx (global)        : 16.2.1
   nx                 : 16.5.5
   @nx/js             : 16.2.2
   @nx/jest           : 16.5.5
   @nx/linter         : 16.5.5
   @nx/workspace      : 16.5.5
   @nx/devkit         : 16.5.5
   @nx/eslint-plugin  : 16.5.5
   @nx/nest           : 16.5.5
   @nx/node           : 16.5.5
   @nrwl/tao          : 16.5.5
   @nx/webpack        : 16.5.5
   typescript         : 5.1.6
   ---------------------------------------
   Community plugins:
   @jscutlery/semver         : 3.1.0
   @nx-tools/nx-container    : 5.0.2
   @nx/rspack                : 16.4.0
   @webundsoehne/nx-builders : 6.1.12
   ---------------------------------------
   Local workspace plugins:
         @beyondclicksai/gateway
         @beyondclicksai/amazon
         @beyondclicksai/core
   ---------------------------------------
   The following packages should match the installed version of nx
     - @nx/js@16.2.2
     - @nrwl/js@16.2.2

   To fix this, run `nx migrate nx@16.5.5`

Failure Logs

@nx/js  16.2.1 to 16.6.0 breaks nestjs + mikroorm + rspack.

[Nest] 19541  - 08/06/2023, 1:48:41 PM     LOG [MikroORM] [discovery] ORM entity discovery started, using ReflectMetadataProvider
[Nest] 19541  - 08/06/2023, 1:48:41 PM     LOG [MikroORM] [discovery] - processing entity Account
[Nest] 19541  - 08/06/2023, 1:48:41 PM     LOG [MikroORM] [discovery] - processing entity AbstractEntity
[Nest] 19541  - 08/06/2023, 1:48:41 PM   ERROR [ExceptionHandler] Account entity is missing @PrimaryKey()
MetadataError: Account entity is missing @PrimaryKey()
@Directive(`@key(fields: “id”)`)
@ObjectType()
@Entity({ tableName: ‘ACCOUNTS’ })
export class Account extends AbstractEntity {...}

......
@ObjectType({ isAbstract: true })
@Entity({ abstract: true })
export class AbstractEntity {
  @PrimaryKey()
  _id: string = randomUUID();
....
}

to reproduce you can try https://github.com/kodeine/NX/

nx serve rspack-test

it works fine on commit 4d69223 but on 5f4d4d9 it gives above error, rspack + nx were updated in last commit.

@nx/js 16.2.1 to 16.6.0 breaks nestjs + mikroorm + rspack.



### Operating System

- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)

### Additional Information

_No response_
mandarini commented 1 year ago

Hi there @kodeine ! Thanks for filing an issue!

I cloned your repo and:

I tried npm i but I got the following error: https://app.warp.dev/block/EghamICNTaW2H5sc5hvAxX. I deleted package-lock.json and tried re-installing and I got the same issue. I ended up --force installing, which is definitely not optimal (and bug-prone, I suppose?). So maybe the dependencies are a bit messed up in this case?

I just noticed in your nx report that there's a mismatch in the versions of your Nx packages. For Nx to work properly, all @nx/* packages should have the same version! Your Nx report as you posted it:

   nx                 : 16.5.5
   @nx/js             : 16.2.2
   @nx/jest           : 16.5.5
   @nx/linter         : 16.5.5
   @nx/workspace      : 16.5.5
   @nx/devkit         : 16.5.5
   @nx/eslint-plugin  : 16.5.5
   @nx/nest           : 16.5.5
   @nx/node           : 16.5.5
   @nrwl/tao          : 16.5.5
   @nx/webpack        : 16.5.5

In the repo that you shared, the versions are indeed aligned. And I can reproduce your issue, however ONLY if I --force install, as I said.

So, in conclusion, I do think that the issue could be in your dependencies, since npm threw that error when trying to install. At the moment, you cannot install anything unless you --force it, so it's clear that there's an issue there with the version mismatches..

kodeine commented 1 year ago

@mandarini thank you for looking into this.

Thank you

kodeine commented 11 months ago

@mandarini @AgentEnder sorry for the tag. Is there any update on this?

mandarini commented 11 months ago

Hi @kodeine ! Let me look into this, again.

mandarini commented 11 months ago

@kodeine yeah I could finally successfully reproduce your issue, but I still cannot figure out why it's happening. The issue it seems to start happening at Nx version 16.3.0. So one version up from 16.2.1 where it's working.

I see in your commit history that there was an issue already with mikro-orm and rspack. Is this the same issue, which surfaced again with your upgrade to a newer version than 16.2.1?

In any case, these are all the changes to the @nx/js package between versions 16.2.1 and 16.3.0 (click to compare), and I'm trying to figure out which change could have affected mikro-orm again:

js: postProcessInlinedDependencies throwing error on movePackage (#16127) (dfa19f5)
js: set node_env when building with esbuild (#17251) (923e6d8)
js: sourcemaps should work with js:node executor (#17261) (f01cdca)
js: log config file errors correctly (#17311) (2865b8d)
js: should check for all possible prettierrc formats before creating a default one (#17157) ([911f753](911f753...
js: add location none to verdaccio executor (#17319) (72b0f55)
js: allow root js lib project to be generated (#17245) (3634abb)

But again I would like to know if this is the same error you experienced before, please.

Thank you for your patience!

Update

I created my forks with the repros and steps to repro:

What I did, to make sure all the rest of the package versions are as expected, I used this commit, which is the last commit before you upgrade to Nx version 16.6.0, and ran nx migrate 16.3.0. Indeed, that's where the PrimaryKey error first appears. Then I made a new branch off of that one, and I only downgraded the @nx/js package. And there, the PrimaryKey error disappears.

kodeine commented 11 months ago

@mandarini Thank you for looking into this, to answer your question, i don't think i faced this issue previously. i was trying to use ts-node-dev instead of ts-node near to that commit you mentioned. but couldnt make ts-node-dev work.

mandarini commented 11 months ago

@kodeine, @jaysoo took over and found the issue! :D

Can you try setting "sourceMap": false in your project.json, even for development? This should fix it.

kodeine commented 11 months ago

@mandarini just confirmed and it works, wow could never have thought sourceMap would fix it. Thanks a bunch to @jaysoo as well as you.

mandarini commented 11 months ago

i can keep sourceMap true in production? or this is a temporary fix?

Not sure, you can try it out and see? something is generating wrong sourcemaps, maybe on the rspack side.

should i be doing nx migrate latest

yes, definitely! I already tried it in your project, and it worked! :) Which it always does hehe

kodeine commented 11 months ago

@mandarini thank you so much, i have shared this thread with RsPack team. Hopefully we will be able to find the root cause for this source maps issue.

mandarini commented 11 months ago

I will close this issue now, but if it turns out it's on the Nx side, we can reopen!

github-actions[bot] commented 10 months ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.