Skip to content

NxTsConfigPaths - buildLibsFromSource incorrect build command #31333

Closed
@raymondboswel

Description

@raymondboswel

Current Behavior

When buildLibsFromSource is false, I found that Nx would try and serve my libraries. Digging into the plugin I came across this block of code:

if (config.command === 'serve') {
          const buildableLibraryDependencies = dependencies
            .filter((dep) => dep.node.type === 'lib')
            .map((dep) => dep.node.name)
            .join(',');
          const buildCommand = `npx nx run-many --target=${process.env.NX_TASK_TARGET_TARGET} --projects=${buildableLibraryDependencies}`;
          config.plugins.push(nxViteBuildCoordinationPlugin({ buildCommand }));
        }

Debugging it I saw that NX_TASK_TARGET_TARGET evaluates to 'serve'. When I created a copy of this plugin into my project, and set --target=build, everything worked as expected. I'm not sure whether I have a misconfiguration somewhere on my side, but either NX_TASK_TARGET_TARGET is initialized with the wrong value in my project, or there's a bug in the above snippet.

Thanks!

Expected Behavior

When buildLibsFromSource is set to false, it should only build the source libs and not try to serve them.

GitHub Repo

No response

Steps to Reproduce

  1. Create a Vite/React application
  2. Create a library project (in my case it's a library that uses Solid-element to export web components. Since both React and Solid use JSX, but use it differently, the library has to be built in a separate compilation.
  3. In the Vite/React application configure NxTsConfigPaths with buildLibsFromSource: false.
  4. Run the application.

I can create a reproduction repo if necessary.

Nx Report

Node           : 22.12.0
OS             : linux-x64
Native Target  : x86_64-linux
pnpm           : 9.15.0

nx (global)        : 20.7.2
nx                 : 20.5.0
@nx/js             : 20.5.0
@nx/eslint         : 20.5.0
@nx/workspace      : 20.5.0
@nx/devkit         : 20.5.0
@nx/eslint-plugin  : 20.5.0
@nx/playwright     : 20.5.0
@nx/react          : 20.5.0
@nx/storybook      : 20.5.0
@nx/vite           : 20.5.0
@nx/web            : 20.5.0
@nx/webpack        : 20.5.0
typescript         : 5.7.3
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/playwright/plugin
@nx/webpack/plugin

Failure Logs

Package Manager Version

No response

Operating System

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

Additional Information

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions