Currently, I am in the process of creating an npm package specifically designed for nextjs projects. Everything has been going smoothly so far. However, my package includes multiple server components and one client component. This particular file contains 'use client' at the top. When trying to load this component in my nextjs project, I encounter the following error:
Module parse failed: Unexpected token (7:43)
You may need an appropriate loader to handle this file type, as currently no loaders are configured to process this file. For more information on loaders, please visit https://webpack.js.org/concepts#loaders
By removing the 'use client' statement, the error disappears and the component is rendered successfully. Nevertheless, it is essential for me to keep it as a client component in order to utilize certain client methods.
The source files for my package consist of both ts and tsx files, which build into .js and .jsx files in the dist folder. While this setup works well for server components, it seems to present challenges when dealing with client components. How can I resolve this issue?