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

create-next-app (canary): Import of *.module.scss in Client Component causes __webpack_require__.n is not a function crash #67783

Closed
karlhorky opened this issue Jul 15, 2024 · 6 comments · Fixed by #67673
Labels
bug Issue was opened via the bug report template. create-next-app Related to our CLI tool for quickly starting a new Next.js application. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation. Webpack Related to Webpack with Next.js.

Comments

@karlhorky
Copy link
Contributor

Link to the code that reproduces this issue

https://github.com/karlhorky/repro-next-js-v15-react-rc-0-sass-webpack-require-not-a-function

To Reproduce

  1. Clone the reproduction repo above (see reproduction repo setup steps below)
  2. Start the app in development (next dev)
  3. Click on the link to navigate to the /non-home page
  4. Observe the error (if the error doesn't appear, it's possible that webpack reloaded the page for you automatically - ⚠ Fast Refresh had to perform a full reload due to a runtime error. warning in the terminal as seen in the video - you may need to repeat step 2 and 3 a few times to see the page-blocking warning):
TypeError: __webpack_require__.n is not a function
    at eval (ClientComponent.tsx:7:127)
    at (app-pages-browser)/app/ClientComponent.tsx (http://localhost:3000/_next/static/chunks/app/non-home/page.js:48:1)
    at options.factory (webpack.js?v=1721063046656:701:31)
    at __webpack_require__ (webpack.js?v=1721063046656:37:33)
    at fn (webpack.js?v=1721063046656:357:21)
    at requireAsyncModule (react-server-dom-webpack-client.browser.development.js:143:17)
    at eval (react-server-dom-webpack-client.browser.development.js:198:16)

The above error occurred in the <NotFoundErrorBoundary> component.

React will try to recreate this component tree from scratch using the error boundary you provided, ReactDevOverlay.

    at Lazy
    at NonHome (Server)
    at InnerLayoutRouter (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:229:11)
    at RedirectErrorBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/redirect-boundary.js:74:9)
    at RedirectBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/redirect-boundary.js:82:11)
    at NotFoundBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/not-found-boundary.js:84:11)
    at LoadingBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:327:11)
    at ErrorBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/error-boundary.js:160:11)
    at InnerScrollAndFocusHandler (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:139:9)
    at ScrollAndFocusHandler (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:214:11)
    at RenderFromTemplateContext (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/render-from-template-context.js:16:44)
    at OuterLayoutRouter (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:348:11)
    at InnerLayoutRouter (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:229:11)
    at RedirectErrorBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/redirect-boundary.js:74:9)
    at RedirectBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/redirect-boundary.js:82:11)
    at NotFoundErrorBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/not-found-boundary.js:76:9)
    at NotFoundBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/not-found-boundary.js:84:11)
    at LoadingBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:327:11)
    at ErrorBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/error-boundary.js:160:11)
    at InnerScrollAndFocusHandler (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:139:9)
    at ScrollAndFocusHandler (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:214:11)
    at RenderFromTemplateContext (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/render-from-template-context.js:16:44)
    at OuterLayoutRouter (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/layout-router.js:348:11)
    at body
    at html
    at RootLayout (Server)
    at RedirectErrorBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/redirect-boundary.js:74:9)
    at RedirectBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/redirect-boundary.js:82:11)
    at NotFoundErrorBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/not-found-boundary.js:76:9)
    at NotFoundBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/not-found-boundary.js:84:11)
    at DevRootNotFoundBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/dev-root-not-found-boundary.js:33:11)
    at ReactDevOverlay (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/react-dev-overlay/app/ReactDevOverlay.js:87:9)
    at HotReload (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/react-dev-overlay/app/hot-reloader-client.js:344:11)
    at Router (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/app-router.js:156:11)
    at ErrorBoundaryHandler (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/error-boundary.js:113:9)
    at ErrorBoundary (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/error-boundary.js:160:11)
    at AppRouter (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/components/app-router.js:551:11)
    at ServerRoot (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/app-index.js:143:46)
    at Root (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/next@15.0.0-canary.67_react-dom@19.0.0-rc.0_react@19.0.0-rc.0_sass@1.77.8/node_modules/next/dist/client/app-index.js:151:11)

Screenshot 2024-07-15 at 19 16 14

Kapture.2024-07-15.at.19.04.14.mp4

Reproduction setup steps

How the reproduction repo was created:

  1. Use create-next-app with TypeScript - adds react@19.0.0-rc.0 and react-dom@19.0.0-rc.0
  2. Remove starter content from pages and layout
  3. pnpm add sass
  4. Add a non-home/page.tsx
  5. Create ClientComponent.tsx and ClientComponent.module.scss with 'use client'
  6. Import <ClientComponent> in non-home/page.tsx
  7. Link to /non-home from app/page.tsx using next/link

Current vs. Expected behavior

I expected no error when using next/link to navigate to a Client Component with a *.module.scss import, but I observed an error

Maybe the canary template for create-next-app needs to be updated to the react@19.0.0-rc-6f23540c7d-20240528 and react-dom@19.0.0-rc-6f23540c7d-20240528 versions

While this demo does not crash with a page-blocking error very often (as seen in the video) more complicated apps crash consistently.

Provide environment information

Node.js v20.15.0

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.5.0: Wed May  1 20:16:51 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 20.15.0
  npm: 10.7.0
  Yarn: N/A
  pnpm: 9.5.0
Relevant Packages:
  next: 15.0.0-canary.67 // Latest available version is detected (15.0.0-canary.67).
  eslint-config-next: N/A
  react: 19.0.0-rc.0
  react-dom: 19.0.0-rc.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

create-next-app, Navigation, Webpack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Updating to the react@19.0.0-rc-6f23540c7d-20240528 and react-dom@19.0.0-rc-6f23540c7d-20240528 versions as are in the App Router reproduction template

But most users using create-next-app@canary will not know to do this.

@karlhorky karlhorky added the bug Issue was opened via the bug report template. label Jul 15, 2024
@github-actions github-actions bot added create-next-app Related to our CLI tool for quickly starting a new Next.js application. Navigation Related to Next.js linking (e.g., <Link>) and navigation. Webpack Related to Webpack with Next.js. labels Jul 15, 2024
@karlhorky
Copy link
Contributor Author

karlhorky commented Jul 15, 2024

Workaround

In speaking with @eps1lon, it appears that versions other than react@19.0.0-rc.0 and react-dom@19.0.0-rc.0 should not be used, since they will cause production problems, whereas this is just a development problem.

Upgrade to react@19.0.0-rc-6f23540c7d-20240528 and react-dom@19.0.0-rc-6f23540c7d-20240528 versions when using latest canary next@15.0.0-canary.67

I retrieved these versions from the App Router reproduction template:

- https://github.com/vercel/next.js/blob/canary/examples/reproduction-template/package.json#L10-L11

@karlhorky
Copy link
Contributor Author

Opened a PR to downgrade the App Router reproduction template to react@19.0.0-rc.0 and react-dom@19.0.0-rc.0 (even though this causes this problem reported above) because apparently non-19.0.0-rc.0 versions have production problems:

samcx pushed a commit that referenced this issue Jul 15, 2024
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

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


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change


Closes NEXT-
Fixes #

-->

### What?

Fix potential production compatibility problems with reproduction
templates

With the possibility of introducing `npx` problems (like what @samcx
[fixed](#66301)) or other dev
problems (like what [I
reported](#67783))

### Why?

According to @eps1lon, versions other than `19.0.0-rc.0` can break in
production

### How?

Downgrade `react` and `react-dom` in App Router reproduction template to
`19.0.0-rc.0`
@eps1lon
Copy link
Member

eps1lon commented Jul 15, 2024

Workaround proposed in #67673

@karlhorky
Copy link
Contributor Author

karlhorky commented Jul 23, 2024

@eps1lon thanks for the PR #67673, merge and publish in next@15.0.0-canary.77 🎉

I've confirmed that this resolves the issue in my reproduction:

pnpm dev

> @ dev /Users/k/p/repro-next-js-v15-react-rc-0-sass-webpack-require-not-a-function
> next dev

  ▲ Next.js 15.0.0-canary.77
  - Local:        http://localhost:3000

 ✓ Starting...
 ✓ Ready in 3s
 ○ Compiling / ...
 ✓ Compiled / in 2.7s (482 modules)
 GET / 200 in 2884ms
 ✓ Compiled /favicon.ico in 176ms (275 modules)
 GET /favicon.ico 200 in 273ms
 ○ Compiling /non-home ...
 ✓ Compiled /non-home in 831ms (546 modules)
 GET /non-home 200 in 426ms
 GET /non-home 200 in 921ms
 GET /non-home 200 in 18ms
 GET / 200 in 80ms
 GET /favicon.ico 200 in 21ms
 GET /non-home 200 in 7ms

Here's the diff in the branch:

@eps1lon
Copy link
Member

eps1lon commented Jul 23, 2024

Glad to hear. Thank you for confirming!

Copy link
Contributor

github-actions bot commented Aug 6, 2024

This closed issue has been automatically locked because it had no new activity for 2 weeks. 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 added the locked label Aug 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2024
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. create-next-app Related to our CLI tool for quickly starting a new Next.js application. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants