Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appDir: Module resolution error when using a RSC #45485

Closed
1 task done
kasvith opened this issue Feb 1, 2023 · 7 comments · Fixed by #45971
Closed
1 task done

appDir: Module resolution error when using a RSC #45485

kasvith opened this issue Feb 1, 2023 · 7 comments · Fixed by #45971
Assignees
Labels
bug Issue was opened via the bug report template.

Comments

@kasvith
Copy link

kasvith commented Feb 1, 2023

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.3.0: Thu Jan  5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000
Binaries:
  Node: 16.19.0
  npm: 8.19.3
  Yarn: 1.22.19
  pnpm: 7.26.0
Relevant packages:
  next: 13.1.7-canary.1
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue

https://github.com/kasvith/next13-remirror-react-renderer-error.git

To Reproduce

Describe the Bug

I want to render React Nodes with React Remirror Renderer(it doesn't load the Editor and produces React Nodes from a given JSON, similar to how MDX works)

So i wanted to use it as a Server Component,
This gives me a weird error like

error - ./node_modules/@remirror/core-utils/dist/remirror-core-utils.js
Attempted import error: 'includes' is not exported from '@remirror/core-helpers' (imported as 'includes').

Import trace for requested module:
./node_modules/@remirror/core-utils/dist/remirror-core-utils.js
./node_modules/@remirror/core/dist/remirror-core.js
./node_modules/@remirror/preset-react/dist/remirror-preset-react.js
./node_modules/@remirror/react/dist/remirror-react.js
./src/app/page.tsx

But the includes from @remirror/core-helpers is already an exported member.
If i switch to use client, it works fine and renders content

Expected Behavior

To provide a better error or solve this if can

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@kasvith kasvith added the bug Issue was opened via the bug report template. label Feb 1, 2023
@kasvith kasvith changed the title Module resolution error when using a RSC appDir: Module resolution error when using a RSC Feb 1, 2023
@shuding shuding self-assigned this Feb 15, 2023
@shuding
Copy link
Member

shuding commented Feb 15, 2023

After some investigation it seems to be from node_modules/get-dom-document/lib/get-dom-document.node.mjs which imports module ...and it can't be bundled.

Quick workaround is to have experimental.serverComponentsExternalPackages: ['@remirror/react'] in your next.config.js but we will still try to address it inside Next.js.

@kasvith
Copy link
Author

kasvith commented Feb 16, 2023

Thanks for insight @shuding

@shuding
Copy link
Member

shuding commented Feb 16, 2023

I looked deeper and the reason is actually that @remirror/react imports useState inside, which can't be used inside server components. You need "use client" on top of that file:

"use client"

import {
  Callout,
  CodeBlock,
  createIFrameHandler,
  createLinkHandler,
  Doc,
  Heading,
  MarkMap,
  RemirrorRenderer,
  TextHandler,
} from "@remirror/react";

The error message from Next was wrong and it should be fixed in #45971.

ijjk pushed a commit that referenced this issue Feb 16, 2023
Closes #45485.

Currently we always output the first error message from the compiler to
avoid making the CLI noisy. However for RSC the first error can
potentially be the consequence of another error which is the real cause.

In #45485, the first error was `Attempted import error: 'includes' is
not exported from '@remirror/core-helpers'` but it was actually caused
by the failure of bundling a package `get-dom-document`. The package is
one of the deps of another package, and then that package is a dep of
`@remirror/core-helpers`. Everything in the dependency chain failed to
import but we only shows the first one (probably the leaf), which makes
it impossible to debug.

This PR fixes it by throwing a special error when we notice that
something is not bundle-able in RSC. And in the output process we
prioritize RSC bundling and RSC errors first — as they are usually the
cause of other errors.

The new error message looks like this:

<img width="981" alt="CleanShot-2023-02-16-8HUK7vAZ@2x"
src="https://user-images.githubusercontent.com/3676859/219216666-7521ca52-68e0-41ed-9219-4d49535f5645.png">

And by applying that change the error will be resolved.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
@kasvith
Copy link
Author

kasvith commented Feb 16, 2023

@shuding can you point me a file which uses it
I thought current imports doesn't use any state

@shuding
Copy link
Member

shuding commented Feb 17, 2023

@kasvith render.tsx imports @remirror/react, which imports @remirror/extension-react-component and it has useState inside extension-react-component/src/portals/react-portals.tsx.

@kasvith
Copy link
Author

kasvith commented Feb 17, 2023

aha, thanks

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants