Closed
Description
Current Behavior
When trying to use a client component exported in a shared React component library within a Nextjs 13 app using the new NextJS app
directory, Nx strips 'use client';
from the component resulting in the following error provided below.
Expected Behavior
Nx should recognize the 'use client';
syntax so that the component doesn't mount on the server but is instead recognized as a client component.
Steps to Reproduce
- Create a Nextjs app using the Nx generator.
- Enable the
app
directory by addingexperimental: { appDir: true },
tonext.config.js
. - Create a React shared library using the Nx generator.
- Add
const [test, setTest] = useState('test');
to the auto generated component in the React lib. - Add
'use client';
to the top of the component. - Import the React component within the Nextjs app.
- Run
yarn start
. - Notice the error message stating that
'use client';
is required to use client components.
Failure Logs
You're importing a component that imports client-only. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
Environment
NX Report complete - copy this into the issue template
Node : 18.11.0
OS : darwin x64
yarn : 1.22.19
nx : 15.0.13
@nrwl/angular : Not Found
@nrwl/cypress : 15.0.13
@nrwl/detox : Not Found
@nrwl/devkit : 15.0.13
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : 15.0.13
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 15.0.13
@nrwl/js : 15.0.13
@nrwl/linter : 15.0.13
@nrwl/nest : Not Found
@nrwl/next : 15.0.13
@nrwl/node : Not Found
@nrwl/nx-cloud : 15.0.2
@nrwl/nx-plugin : Not Found
@nrwl/react : 15.0.13
@nrwl/react-native : Not Found
@nrwl/rollup : 15.0.13
@nrwl/schematics : Not Found
@nrwl/storybook : 15.0.13
@nrwl/web : 15.0.13
@nrwl/webpack : 15.0.13
@nrwl/workspace : 15.0.13
typescript : 4.8.4
Local workspace plugins:
Community plugins: