question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RSC: client components from node_modules doesn't work

See original GitHub issue

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101
    Binaries:
      Node: 14.17.0
      npm: 8.5.5
      Yarn: 1.22.15
      pnpm: 6.11.0
    Relevant packages:
      next: 12.1.1-canary.14
      react: 18.0.0-rc.2
      react-dom: 18.0.0-rc.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Reproduction

// pages/index.server.js
import Fooding from 'fooding'

export default () => <Fooding />

Create a package in node_modules called fooding:

// package.json
{ "name": "fooding", "exports": "./index.js" }

// index.js
export { default } from './fooding.client.js'

// fooding.client.js
import { useState } from 'react'
export default () => {
   const [text] = useState('Who is')
   return text + ' fooding?'
}

When you try visiting the built / page it shows error Module not found: Package path ./?__sc_server__ is not exported from package test-app/node_modules/fooding (see exports field in test-app/node_modules/fooding/package.json) in console

Expected Behavior

Shared and client components should behave like the ones in source folders

  • Visit the / page
  • Display Who is fooding? and hydrate without error

To Reproduce

  • Use the reproduction above
  • run next dev
  • visit localhost:3000

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
huozhicommented, Mar 23, 2022

hey @hamlim there’re few changes we need to tweak on next.js side which we’re still investigating what’s the proper way now, not only the loader might need to change. will keep posted here once we have ant further findings. thanks

1reaction
huozhicommented, Nov 16, 2022

Hi, with the next 13.x, you can make it work with app directory and server components. You can checkout the new server and client components convention in the beta docs here. I did some tests it works locally for me.

Sample code

// app/page.js
import React from 'react';
import ClientFoo from 'client-foo';

export default function Page() {
  return <ClientFoo />
}
// node_modules/client-foo/index.js
'use client'

import { useState } from 'react'

export default function Foo() {
  const [count] = useState(0)
  return count
}

I’ll close this issue as resolved. If you still have any issue with the it, please file a new issue with the reproduction. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm install doesn't create node_modules directory
I created a package.json file at the root, which contained a simple JSON obj: { "name": "please-work" }. On the next npm install...
Read more >
Npm start doesn't work - M220JS - MongoDB
I exactly followed the readme lecture, everything went fine, but when I used the npm start command, I got the following error.
Read more >
package.json - npm Docs
Description. This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just...
Read more >
Error - [tsc] node_modules/@fluentui/react/lib/components ...
Which type of client-side component to create? ... anymatch provides its own type definitions, so you do not need this installed.
Read more >
Blog - Next.js 13
Next.js 13 introduces layouts, React Server Components, ... the user does not have to wait for the entire page to load before they...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found