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

Build is broken in NX 16.6.0 #18562

Closed
1 of 4 tasks
abrahamsaanchez opened this issue Aug 10, 2023 · 12 comments
Closed
1 of 4 tasks

Build is broken in NX 16.6.0 #18562

abrahamsaanchez opened this issue Aug 10, 2023 · 12 comments

Comments

@abrahamsaanchez
Copy link

Current Behavior

I updated to NX 16.6.0 and I created a library with an interface, them I implement this interface in another library and when I try to build the implementation an "Cannot find module" or "File is not under 'rootDir'" error is raised.

Expected Behavior

I should be able to build the library without errors.

GitHub Repo

https://github.com/abrahamsaanchez/build-error

Steps to Reproduce

  1. Create an NX workspace.
  2. Create a library that contains an interface.
  3. Create a library that have a class implementing the interface.
  4. Build the library that implements the interface.

Nx Report

Node   : 18.15.0
OS     : linux-x64
npm    : 9.5.0

nx                 : 16.6.0
@nx/js             : 16.6.0
@nx/jest           : 16.6.0
@nx/linter         : 16.6.0
@nx/workspace      : 16.6.0
@nx/devkit         : 16.6.0
@nx/eslint-plugin  : 16.6.0
@nx/node           : 16.6.0
@nrwl/tao          : 16.6.0
typescript         : 5.1.6
---------------------------------------
Local workspace plugins:
      @build-error/infrastructure.translator
      @build-error/domain.interfaces.translator

Failure Logs

Compiling with SWC for infrastructure-translator-in-memory-translator...
Successfully compiled: 2 files with swc (10.98ms)
packages/domain/interfaces/translator/src/index.ts:1:15 - error TS6059: File '.../build-error/packages/domain/interfaces/translator/src/lib/translator.ts' is not under 'rootDir' 'packages/infrastructure/translator/in-memory-translator'. 'rootDir' is expected to contain all source files.

> 1 | export * from './lib/translator';
    |               ^
  2 | 

packages/infrastructure/translator/in-memory-translator/src/lib/in-memory-translator.ts:1:28 - error TS6059: File '.../build-error/packages/domain/interfaces/translator/src/index.ts' is not under 'rootDir' 'packages/infrastructure/translator/in-memory-translator'. 'rootDir' is expected to contain all source files.

> 1 | import { Translator } from '@build-error/domain.interfaces.translator';
    |                            ^
  2 | 
  3 | export class InMemoryTranslator implements Translator {
  4 |   translate(): void {

Found 2 errors.

Operating System

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

Additional Information

In other project, I have some interfaces created before updating to NX 16.6.0 and I can build all the libraries that depends on this interfaces, but I can not build a library created after updating to NX 16.6.0 that use the new interface or a old interface.

@FrozenPandaz
Copy link
Collaborator

How exactly did you configure the workspace? It seems to have some configuration issues.

  1. If you are using the package-based preset, you must make dependencies via package.json.
  2. If not, you can remove the "extends": "nx/presets/npm.json", extension in nx.json and the dependencies will be analyzed.
  3. The workspace is missing target defaults for build to depend on ^build which is necessary for building libraries which depend on other libraries in the correct order.

@abrahamsaanchez
Copy link
Author

@FrozenPandaz I use the create-nx-workspace tool, I don't remember if I choose integrated or package based monorepo... I can give you more details in a few days if the repo provided do not help you

@FrozenPandaz
Copy link
Collaborator

Yes please, more details would help. I suspect the build logic is okay. However, the config is wrong so I would like to understand how you got into that state.

@abrahamsaanchez
Copy link
Author

@FrozenPandaz I follow these steps:

  1. Run npx create-nx-workspace@latest
✔ Where would you like to create your workspace? · build-error
✔ Which stack do you want to use? · none
✔ Package-based monorepo, integrated monorepo, or standalone project? · package-based

✔ Enable distributed caching to make your CI faster · No
  1. Run npm i @nx/node
  2. Generate the library with the interface using the NX generator npx nx generate @nx/js:library --name=translator --unitTestRunner=jest --bundler=swc --directory=domain/interfaces --importPath=@build-error/domain.interfaces.translator --publishable=true --simpleName=true --no-interactive
  3. Generate the library with the implementation npx nx generate @nx/js:library --name=in-memory-translator --unitTestRunner=jest --bundler=swc --directory=infrastructure/translator --importPath=@build-error/infrastructure.translator.in-memory-translator --publishable=true --simpleName=true --no-interactive
  4. Implement the interface in the class.

When you build the implementation, the error is raised.

Can you tell me what is wrong with the configuration? Like I said, the same thing happens in a old project when I update NX (also fails in NX 17.0.0)

@jd4u
Copy link

jd4u commented Aug 24, 2023

create project as per your steps above using nx latest. The build works at first setup. While adding "extends": "nx/presets/npm.json", in nx.json, the build fails with 'rootDir' requires all sources in it error. Once again, removed the line and it works.

The line is in your github project. (github repo fails to install npm packages with some local download error.)

@jorgeramirezamora
Copy link

I am also experiencing this going from 16.5.5 to 16.6.0.

This error only happens when the buildable library is using @nx/rollup:rollup. It does happen when is @nx/vite:build @FrozenPandaz

@mandarini
Copy link
Member

mandarini commented Oct 25, 2023

@abrahamsaanchez and anyone else, is it possible that your build target names (of two interdependent libs) are different? This bug can appear if you are importing one buildable lib into the other, and the build target names are different.

related: #11289

For anyone having that error, solution: #17798 (comment)

@abrahamsaanchez
Copy link
Author

@abrahamsaanchez and anyone else, is it possible that your build target names (of two interdependent libs) are different? This bug can appear if you are importing one buildable lib into the other, and the build target names are different.

related: #11289

All my build targets are named build so this is not the error in my case

@mandarini
Copy link
Member

@abrahamsaanchez thanks, good to know! Just checking! :)

@leosvelperez
Copy link
Member

@abrahamsaanchez are you still facing this issue? I can't access the reproduction provided in the issue description.

Based on this thread, and as explained in #18562 (comment), you seem to have "extends": "nx/presets/npm.json" in nx.json. That preset is meant to be used in package-based repos and it disables analyzing your TypeScript file sources to identify the dependencies between projects. Therefore, dependencies between projects are not picked up automatically based on your source code imports.

You have two ways of addressing this:

  • Delete "extends": "nx/presets/npm.json" from nx.json, or
  • Configure your dependencies in your package.json files

Also, make sure your target defaults are correctly configured. You can see an example setting up a package-base workspace in https://nx.dev/getting-started/tutorials/package-based-repo-tutorial.

Copy link

github-actions bot commented Dec 9, 2023

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants