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

[NEXT-947] The experimental-runtime fails with ReferenceError: self is not defined when used inside a route group #43458

Closed
1 task done
shadcn opened this issue Nov 28, 2022 · 10 comments · Fixed by vercel/vercel#9764
Assignees
Labels
area: app App directory (appDir: true) Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@shadcn
Copy link
Contributor

shadcn commented Nov 28, 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: x64
  Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64
Binaries:
  Node: 16.18.0
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: 7.13.5
Relevant packages:
  next: 13.0.5
  eslint-config-next: 13.0.5
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

Using the experimental-edge runtime fails with the following error when used inside a route group.

ReferenceError: self is not defined
    at Object.<anonymous> (/var/task/.next/server/app/(marketing)/stats/page.js:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.requirePage (/var/task/node_modules/.pnpm/next@13.0.6-canary.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/server/require.js:88:12)
    at /var/task/node_modules/.pnpm/next@13.0.6-canary.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/server/load-components.js:37:73
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  page: '/stats'
}
RequestId: Error: Runtime exited with error: exit status 1
Runtime.ExitError

Given the following file structure:

app
├── page.tsx ✅
├── nested
│   └── page.tsx ✅
├── (group)
│   └── group
│       └── page.tsx ❌
└── (another-group)
    └── another-group
        └── page.tsx ❌  

With export const runtime = "experimental-edge", the following is observed:

  • / - Works
  • /nested - Works
  • /group - Fails
  • /another-group - Fails

I checked if having a layout.tsx has any effect on grouping. It does not.

Expected Behavior

Expects the experimental-edge runtime to work inside route groups.

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

https://github.com/shadcn/next-debug-edge-runtime

To Reproduce

See the links below:

  1. experimental-edge runtime works for root page: https://next-debug-edge-runtime.vercel.app
  2. experimental-edge runtime works for a nested page: https://next-debug-edge-runtime.vercel.app/nested-with-layout
  3. experimental-edge runtime does not work for a grouped page with layout: https://next-debug-edge-runtime.vercel.app/group-no-layout
  4. experimental-edge runtime does not work for a grouped page without layout: https://next-debug-edge-runtime.vercel.app/group-with-layout

NEXT-947

@shadcn shadcn added the bug Issue was opened via the bug report template. label Nov 28, 2022
@timneutkens timneutkens added kind: bug area: app App directory (appDir: true) Runtime Related to Node.js or Edge Runtime with Next.js. and removed bug Issue was opened via the bug report template. labels Nov 29, 2022
kodiakhq bot pushed a commit that referenced this issue Nov 29, 2022
Currently the generated matcher will be `"regexp": "^\(group\)/group$"` for groups which doesn't match the correct route. This is somehow related to #43458, but it only fixes the problem partially. Some other changes need to be made in the build process.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] 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)
@pksorensen
Copy link

#43662 - my example was the /pages/index.tsx , and i dont see that is covered in the senarie mentioned here so why is it a dublicate?

@shadcn
Copy link
Contributor Author

shadcn commented Dec 6, 2022

@shuding Thanks for the fix in #43549.

I tested with the latest canary 13.0.7-canary.1 but still seeing the same error.

@pksorensen
Copy link

people are reporting issues on #43662 that is not related to route groups. As i see it , fetch do not work in edge runtime.

@alvarlagerlof
Copy link

I just got the error on 13.1.1, not in a route group. Just /test/[name].

@marketsystems
Copy link

marketsystems commented Feb 14, 2023

fails with the same message "ReferenceError: self is not defined" on windows for nested pages even now, yet build works fine if you do it on linux (ubuntu) even though all packages and binaries are the same version as windows (even when updating both to next@canary latest

I guess it is some sort of path issue that doesnt resolve in windows but resolves fine in linux

@kaceycleveland
Copy link

Getting this on deploying to vercel on 13.2.4

@huozhi huozhi added bug linear: next Confirmed issue that is tracked by the Next.js team. and removed bug labels Apr 5, 2023
@jankaifer jankaifer added linear: next Confirmed issue that is tracked by the Next.js team. and removed linear: next Confirmed issue that is tracked by the Next.js team. kind: bug labels Apr 5, 2023
@jankaifer jankaifer changed the title The experimental-runtime fails with ReferenceError: self is not defined when used inside a route group [NEXT-947] The experimental-runtime fails with ReferenceError: self is not defined when used inside a route group Apr 5, 2023
@jankaifer jankaifer assigned shuding and unassigned shuding Apr 5, 2023
@ijjk ijjk assigned ijjk and unassigned shuding Apr 6, 2023
ijjk added a commit to vercel/vercel that referenced this issue Apr 7, 2023
This ensures we use the correct short name when generating edge
functions with route groups from app directory.

Example deployment with fix can be seen here
https://next-debug-edge-runtime-1ar7agbjh-vtest314-ijjk-testing.vercel.app/group-no-layout

Fixes: vercel/next.js#43458
@ijjk
Copy link
Member

ijjk commented Apr 11, 2023

Hi, this should now be available in production, please re-deploy your project and give it a try!

@alvarlagerlof
Copy link

alvarlagerlof commented Apr 12, 2023

Hi, this should now be available in production, please re-deploy your project and give it a try!

Did a rebuild of my draft PR using the Edge for one page (in a route group). It just started working!

@barthicus
Copy link

I also rebuild my projects that previously failed with 500 error. Now they are working fine. 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 May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.