-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Current Behavior
When creating a buildable Next.js UI library project with Vite, NX will generate a libs/[project]/src/server.ts
file "to export React server components" from.
Contents of libs/[project]/src/server.ts
:
// Use this file to export React server components
export * from './lib/hello-server';
The only issue with this is that currently, by default no entry points are setup in the project's package.json
and vite.config.ts
files. With this misconfiguration, server components cannot be imported into other projects within the mono-repo unless they are exported from the libs/[project]/src/index.ts
file -- but this one states that it should be reserved for components that use the "use client" directive explicitly.
Contents of libs/[project]/src/index.ts
:
// Use this file to export React client components (e.g. those with 'use client' directive) or other non-server utilities
export * from './lib/client-component';
Expected Behavior
When creating a new buildable Next.js lib (i.e. selecting a bundler), NX will automatically configure entry points for building/bundling/exporting server components in the package.json
exports field, and the vite.config.ts
config file.
GitHub Repo
https://github.com/jtw-r/nx-vite-next-bug
Steps to Reproduce
Check lib build output:
- Open attached repo
- Run
npm i && npx nx build buildable-ui
- Run
cd libs/buildable-ui/dist && ls
- See how there is no built
server.mjs
entry point file
--
Try to import the hello-server
component in the website app project:
- Open
apps/website/app/page.tsx
- Try to import the
HelloServer
component from the monorepo's@nx-vite-next-bug/buildable-ui
library.
Nx Report
Node : 20.11.0
OS : darwin-arm64
Native Target : aarch64-macos
npm : 10.2.4
nx (global) : 20.3.0
nx : 21.1.2
@nx/js : 21.1.2
@nx/eslint : 21.1.2
@nx/workspace : 21.1.2
@nx/devkit : 21.1.2
@nx/module-federation : 21.1.2
@nx/next : 21.1.2
@nx/react : 21.1.2
@nx/vite : 21.1.2
@nx/web : 21.1.2
@nx/webpack : 21.1.2
typescript : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/next/plugin
@nx/react/router-plugin
@nx/vite/plugin
---------------------------------------
Cache Usage: 1.70 KB / 372.19 GB
Failure Logs
Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
Please backport a fix to NX v20 if possible; my main repo is using this version, but it is present in v21 too.