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

v13 Server Components - Webpack error running data fetching method #43328

Closed
1 task done
jens-ox opened this issue Nov 24, 2022 · 5 comments
Closed
1 task done

v13 Server Components - Webpack error running data fetching method #43328

jens-ox opened this issue Nov 24, 2022 · 5 comments
Labels
area: app App directory (appDir: true) kind: bug Confirmed bug that is on the backlog

Comments

@jens-ox
Copy link

jens-ox commented Nov 24, 2022

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 21.6.0: Wed Aug 10 14:28:35 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T8101
Binaries:
  Node: 16.18.0
  npm: 8.19.2
  Yarn: 1.22.17
  pnpm: 7.1.8
Relevant packages:
  next: 13.0.6-canary.0
  eslint-config-next: 13.0.5
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome 107.0.5304.110 (Official Build) (arm64)

Describe the Bug

I'm using simple-git to get the latest commit hash from a remote repo. While this works fine in API routes (see pages/api/hello in the repro repo below), doing so in an app page (see app/page.tsx) causes a server runtime error:

TypeError: (0 , simple_git__WEBPACK_IMPORTED_MODULE_0__.default) is not a function

image

Expected Behavior

I would have assumed that the execution context is the same for server-side data loading and API handlers.

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://github.com/jens-ox/nextjs-bug-app-ssr

To Reproduce

  • clone repo
  • pnpm install
  • pnpm dev
  • GET /api/hello --> works correctly and returns the latest commit hash from the Next.js repo
  • Open http://localhost:3000 in your browser -> will cause server error
@jens-ox jens-ox added the bug Issue was opened via the bug report template. label Nov 24, 2022
@balazsorban44
Copy link
Member

balazsorban44 commented Nov 24, 2022

Based on the documentation, there is no default export in the case of ESM imports, but there still seems to be an issue as import * as git from "simple-git" still gives an empty Module object. Potentially introduced in either #42741 or #42767

@balazsorban44 balazsorban44 added kind: bug Confirmed bug that is on the backlog area: app App directory (appDir: true) and removed bug Issue was opened via the bug report template. labels Nov 24, 2022
@jens-ox
Copy link
Author

jens-ox commented Nov 25, 2022

The error also occurs with import { simpleGit } from 'simple-git' - should I update the repro?

@jens-ox
Copy link
Author

jens-ox commented Nov 25, 2022

Seems like this was fixed in #43349 - added simple-git to serverComponentsExternalPackages, which fixes the issue. However, I only found this by trying to create a failing e2e test (i.e. adapting e2e/app-dir/app-external). @balazsorban44 feel free to close this, but maybe some documentation would be helpful to others. If I can help documenting this (or helping out with aligning the ESM/CJS resolution logic differences between client and server) let me know ☺️

@balazsorban44
Copy link
Member

Closing based on #43349 👍

Documentation can be found here: https://beta.nextjs.org/docs/api-reference/next.config.js#servercomponentsexternalpackages

If a dependency is using Node.js specific features, you can choose to opt-out specific dependencies from the Server Components bundling and use native Node.js require.

@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 Dec 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) kind: bug Confirmed bug that is on the backlog
Projects
None yet
Development

No branches or pull requests

2 participants