-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
'rootDir' is expected to contain all source files. Bundle failed: test-icons #11289
Comments
To help everyone understand what's going on, here is the process of how I found the root cause. What's the problemSay we have a monorepo, with several libraries inside, let's name them
import { jim } from '@project-org/lib-b';
import { john } from '@project-org/lib-c'; Path aliases are defined in root
Here is the essential part of {
"sourceRoot": "libs/lib-a/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"commands": ["nx run lib-a:build-lib", "nx run lib-a:build-css"],
"parallel": false
}
},
"build-lib": {
"executor": "@nrwl/web:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/lib-a",
"tsConfig": "libs/lib-a/tsconfig.lib.json",
"project": "libs/lib-a/package.json",
"entryFile": "libs/lib-a/src/index.ts",
}
}
}
} And here is the essential part of {
"sourceRoot": "libs/lib-b/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nrwl/web:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/lib-b",
"tsConfig": "libs/lib-b/tsconfig.lib.json",
"project": "libs/lib-b/package.json",
"entryFile": "libs/lib-b/src/bar.ts",
}
}
}
} And here is the essential part of {
"sourceRoot": "libs/lib-c/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"commands": ["nx run lib-c:build-svg", "nx run lib-c:build-lib"],
"parallel": false
}
},
"build-lib": {
"executor": "@nrwl/web:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/lib-c",
"tsConfig": "libs/lib-c/tsconfig.lib.json",
"project": "libs/lib-c/package.json",
"entryFile": "libs/lib-c/src/tor.ts",
}
}
}
} All Now when we issue
What's strange is, there's NO such error for Dig into the source code of nx to find the root causeWe can add Let's dive directly into rollup executor then. NOTE the original error says Ah, here it is. But, hmm, still doesn't know what could go wrong. Let's take a look what But hold on, [
{
name: '@project-org/lib-c',
outputs: [ 'dist/libs/lib-c' ],
node: { type: 'lib', name: 'lib-c', data: [Object] }
},
// ...
] However we'll find With this list of dependencies, {
rootDir: '/path-to-monorepo/libs/lib-a/src',
allowJs: false,
declaration: true,
paths: {
'@project/lib-b': [ 'libs/lib-b/src/foo.ts' ],
'@project/lib-c': [ 'dist/libs/lib-c' ],
// ...
}
} Huh? In What's inside However, Now, the question becomes, why is Let's get back to And next is the essential part.
{
"lib-b": {
"name": "lib-b",
"type": "lib",
"data": {
"root": "libs/lib-b",
"sourceRoot": "libs/lib-b/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nrwl/web:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/lib-b",
"tsConfig": "libs/lib-b/tsconfig.lib.json",
"project": "libs/lib-b/package.json",
"entryFile": "libs/lib-b/src/bar.ts",
"external": ["react/jsx-runtime"],
"rollupConfig": "@nrwl/react/plugins/bundle-rollup",
}
}
},
"files": [
// ...
]
}
},
"lib-c": {
"name": "lib-c",
"type": "lib",
"data": {
"root": "libs/lib-c",
"sourceRoot": "libs/lib-c/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"commands": ["nx run lib-c:build-svg", "nx run lib-c:build-lib"],
"parallel": false
}
},
"build-lib": {
"executor": "@nrwl/web:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/lib-c",
"tsConfig": "libs/lib-c/tsconfig.lib.json",
"project": "libs/lib-c/package.json",
"entryFile": "libs/lib-c/src/tor.ts",
"external": ["react/jsx-runtime"],
"rollupConfig": "@nrwl/react/plugins/bundle-rollup",
}
}
},
"files": [
// ...
]
}
}
}
Let's look at the definition of node.data.targets &&
node.data.targets[target] &&
node.data.targets[target].executor !== '' As for SolutionTo make nx thinks {
"sourceRoot": "libs/lib-b/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"commands": ["nx run lib-b:build-lib"],
"parallel": false
}
},
"build-lib": {
"executor": "@nrwl/web:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/lib-b",
"tsConfig": "libs/lib-b/tsconfig.lib.json",
"project": "libs/lib-b/package.json",
"entryFile": "libs/lib-b/src/bar.ts",
}
}
}
} To summarize it, all internal dependencies of a library must have a build target of the same name, in order to make nx treat them as buildable. Other workarounds
|
@SunStupic I had an issue like this (if not the same issue). What fixed it for me was adding the I'd be curious to hear if this works for you. |
I'm using |
I had the same issue. I fixed it by updating to the latest Please make sure you either update globally the Example: |
adding the dist path(s) to the tsconfig did the trick for me. |
Thats for sure works, but is hard to develop this way. You have to manually build libraries in correct order. You are also importing now from DIST, means changes you make are not seamless applied to the rest of the project. |
that solved my problems - this is non-obvious, would be great to have some output that helped diagnose this issue when having multiple and interdependent js buildable libraries. Thanks @athrunsun ! |
Any update on this? all workaround mentioned above didn't work for me. |
Changing the tsconfig paths helped compiling the project, but it raises another error `Error: Cannot find module '@my-org/lib-b', because the imported lib path is not changed in the compiled file |
In my case, I noticed that when I moved some files to a different folder, some relative import paths were automatically changed. It was |
I keep getting this error with I keep doing update: not had any further issues on latest 15.9.2. I don’t recommend messing with tsconfigs almost ever (trust the nx team more than ts server) |
Check that the include paths in the tsconfig.lib.json don’t reference files in another library. |
Found issue in --- a/src/executors/rollup/rollup.impl.js
+++ b/src/executors/rollup/rollup.impl.js
@@ -214,7 +214,7 @@ exports.createRollupOptions = createRollupOptions;
function createTsCompilerOptions(config, dependencies, options) {
const compilerOptionPaths = (0, buildable_libs_utils_1.computeCompilerOptionsPaths)(config, dependencies);
const compilerOptions = {
- rootDir: options.projectRoot,
+ rootDir: config.options.rootDir,
allowJs: options.allowJs,
declaration: true,
paths: compilerOptionPaths, Fix also pushed to main repo #19725 |
The issue, as very well explained by @athrunsun, is that if your I will look into if we are planning to address this. Sorry about that! Solution for now: #17798 (comment) |
The As explained (great detective work! 👏🏻 ) by @athrunsun in #11289 (comment), Nx executors that support the incremental builds scenarios, look for targets with the same name as the build target name of the top-level project being built. The found targets' info will be used to collect their output paths and remap on the fly the TS path mappings existing in the tsconfig file at the root of your workspace to point to the compiled source. The remapping is done so we can provide the best possible DX. By default, your projects point to the dependency sources (that's what your IDE will use) and at build time, it will point to the dependency compiled code to avoid building it again. When looking up for the dependencies targets, if they are not found, the TS path mapping will remain pointing to the source code of the dependency and given it's a different project, its location will be outside of the Also, if the dependencies between targets are not correctly configured (using Please note that error will also happen if the dependencies of buildable libraries are not buildable (have a target to build the library). In such cases, no target will be found because there's none and the same error will be thrown. Buildable libraries must depend on other buildable libraries. There are a couple of executors that support inlining non-buildable libraries into buildable libraries, but that feature is highly experimental and it's not recommended. Identifying the buildable target from the dependencies has always been the challenge and we've had a constraint of keeping the target names aligned. Nx generators always generate "build" target, but of course, in real-world scenarios, developers can change those names and use something else. This is often the case when needing to do extra tasks and new targets are added and composed to build a project. In Nx 16.6.0, we introduced a new way to identify the build target of dependent buildable libraries. The new way doesn't rely on the targets having the same name, but rather on the information available in the task graph. It's still key to have the target dependencies correctly configured. This behavior is not yet enabled by default, but you can try it by setting the following env var: We're trying to get feedback whether this new way works as expected before turning it on by default. Could you try it and let us know how it goes? We want to know:
If you already solved your issue by ensuring the same target name, you could still try this and provide feedback. As mentioned above, we want to make sure the new way doesn't break existing scenarios. If it doesn't work for you, please try to provide a reproduction so the feedback is actionable and we can troubleshoot it. |
In my current application, I am integrating non-buildable libraries into a buildable application using @nx/webpack:webpack. However, when attempting to use the swc executor, I encountered an error. My current strategy is to convert all non-buildable libraries into buildable ones, as it seems to be the only viable solution to make this work. |
@7alip Must have saved me hours with your comment. Thank you |
Looks like this error is thrown in 17.3 if library has circular dependency but this happens also using ng-packagr directly might be related to new template build pipeline angular/angular#54571 or bug in TS 5.4.2 microsoft/TypeScript#57750 |
We've started experiencing similar issues with TypeScript 5.4. (we're not using nrwl, but I'm pretty sure that this is the same underlying problem). It seems to be a TypeScript cause as opposed to Angular 17.3. We are seeing it in some library secondary entrypoints, and it isn't clear why it has started happening. Using the TypeScript nightly builds I narrowed it down to working in 5.4.0-dev.20231221, but broken in 5.4.0-dev.20231222 That seems to point to this change as the cause: microsoft/TypeScript#55015 Hopefully this helps to identify the underlying problem. We're still investigating how to address it properly. |
Looks like microsoft/TypeScript#57973 might fix the problem that was introduced in TypeScript 5.4 |
I wasted a lot of time researching this problem because no solution worked for me. |
I had this issue two times, the issue was the name in |
To speed up tests execution. Benchmark 1: nx reset && nx clear-cache && nx run-many -t test Time (mean ± σ): 1.901s ± 0.014s [User: 1.034s, System: 0.188s] Range (min … max): 1.882s … 2.010s 100 runs Benchmark 2: nx reset && nx clear-cache && nx run-many -t test Time (mean ± σ): 1.970s ± 0.030s [User: 1.070s, System: 0.199s] Range (min … max): 1.931s … 2.131s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment)
To speed up tests execution. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.759s ± 0.027s [User: 3.324s, System: 0.219s] Range (min … max): 2.690s … 2.870s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.815s ± 0.018s [User: 1.763s, System: 0.140s] Range (min … max): 1.775s … 1.904s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.668s ± 0.008s [User: 0.802s, System: 0.137s] Range (min … max): 1.643s … 1.689s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
In order to speed up test executions. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.755s ± 0.046s [User: 3.335s, System: 0.221s] Range (min … max): 2.675s … 3.044s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.815s ± 0.018s [User: 1.763s, System: 0.140s] Range (min … max): 1.775s … 1.904s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.642s ± 0.009s [User: 0.792s, System: 0.140s] Range (min … max): 1.616s … 1.682s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
In order to speed up test executions. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.755s ± 0.046s [User: 3.335s, System: 0.221s] Range (min … max): 2.675s … 3.044s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.815s ± 0.018s [User: 1.763s, System: 0.140s] Range (min … max): 1.775s … 1.904s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.642s ± 0.009s [User: 0.792s, System: 0.140s] Range (min … max): 1.616s … 1.682s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
In order to speed up test executions. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.755s ± 0.046s [User: 3.335s, System: 0.221s] Range (min … max): 2.675s … 3.044s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.815s ± 0.018s [User: 1.763s, System: 0.140s] Range (min … max): 1.775s … 1.904s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.642s ± 0.009s [User: 0.792s, System: 0.140s] Range (min … max): 1.616s … 1.682s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
In order to speed up test executions. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.755s ± 0.046s [User: 3.335s, System: 0.221s] Range (min … max): 2.675s … 3.044s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.815s ± 0.018s [User: 1.763s, System: 0.140s] Range (min … max): 1.775s … 1.904s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.642s ± 0.009s [User: 0.792s, System: 0.140s] Range (min … max): 1.616s … 1.682s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
In order to speed up test executions. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.751s ± 0.040s [User: 3.329s, System: 0.220s] Range (min…max): 2.692s … 2.861s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.785s ± 0.017s [User: 1.751s, System: 0.139s] Range (min…max): 1.750s … 1.834s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.657s ± 0.006s [User: 0.800s, System: 0.139s] Range (min…max): 1.623s … 1.679s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
In order to speed up test executions. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.751s ± 0.040s [User: 3.329s, System: 0.220s] Range (min…max): 2.692s … 2.861s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.785s ± 0.017s [User: 1.751s, System: 0.139s] Range (min…max): 1.750s … 1.834s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.657s ± 0.006s [User: 0.800s, System: 0.139s] Range (min…max): 1.623s … 1.679s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
In order to speed up test executions. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.751s ± 0.040s [User: 3.329s, System: 0.220s] Range (min…max): 2.692s … 2.861s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.785s ± 0.017s [User: 1.751s, System: 0.139s] Range (min…max): 1.750s … 1.834s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.657s ± 0.006s [User: 0.800s, System: 0.139s] Range (min…max): 1.623s … 1.679s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
In order to speed up test executions. hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t lint" Time (mean ± σ): 2.751s ± 0.040s [User: 3.329s, System: 0.220s] Range (min…max): 2.692s … 2.861s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t build" Time (mean ± σ): 1.785s ± 0.017s [User: 1.751s, System: 0.139s] Range (min…max): 1.750s … 1.834s 100 runs hyperfine --warmup 5 --prepare "nx reset && nx clear-cache" \ --runs 100 "nx run-many -t test" Time (mean ± σ): 1.657s ± 0.006s [User: 0.800s, System: 0.139s] Range (min…max): 1.623s … 1.679s 100 runs More: - https://docs.nestjs.com/recipes/swc#monorepo - nrwl/nx#11289 (comment) - jestjs/jest#9430 - https://npmjs.com/package/jest_workaround
@Frikki you saved me from tons of hours of debugging and headache, thanks! |
I had the same error when my tsconfig alias path was Once I changed it to a I wonder if this expected @leosvelperez (and thank you for exhaustive explanation). |
Thank you! I had to create the |
Current Behavior
Now when I run
build
command in our repo with multiple publishable libs, I get error like this:Expected Behavior
Expect to build successfully or with a better error message like:
test-core
has nobuild-lib
target.Steps to Reproduce
pnpm i
nx run test-icons:build-lib
Failure Logs
Environment
Workaround
Now the workaround is simple, we need to add
build-lib
for all the publishable packages or we change back to usebuild
.The text was updated successfully, but these errors were encountered: