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

..ReferenceError: self is not defined on edge runtime #43662

Closed
1 task done
pksorensen opened this issue Dec 3, 2022 · 12 comments
Closed
1 task done

..ReferenceError: self is not defined on edge runtime #43662

pksorensen opened this issue Dec 3, 2022 · 12 comments
Labels
bug Issue was opened via the bug report template.

Comments

@pksorensen
Copy link

Verify canary release

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

Provide environment information

PS C:\dev\dps\test\my-app> npx next info

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Enterprise
Binaries:
  Node: 18.12.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.0.6
  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)

Middleware / Edge (API routes, runtime)

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

N/A

To Reproduce

Create new project:
npx create-next-app@latest --ts

add

export const config = {
    runtime: 'experimental-edge',
}

to index.tsx

and npm run build

Describe the Bug

> next build

info  - Linting and checking validity of types
warn  - You are using an experimental edge runtime, the API might change.
info  - Creating an optimized production build
info  - Compiled successfully
    at Object.<anonymous> (C:\dev\dps\test\my-app\.next\server\pages\index.js:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.requirePage (C:\dev\dps\test\my-app\node_modules\next\dist\server\require.js:88:12)
    at C:\dev\dps\test\my-app\node_modules\next\dist\server\load-components.js:37:73
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Expected Behavior

That it build

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@pksorensen pksorensen added the bug Issue was opened via the bug report template. label Dec 3, 2022
@balazsorban44
Copy link
Member

Duplicate of #43458

@cantutar
Copy link

cantutar commented Dec 15, 2022

Having the same issue just started a new project with npx create-next-app@latest --ts and setted the edge-runtime.

next.config.js file

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    runtime: "experimental-edge",
  },
  reactStrictMode: true,
  swcMinify: true,
};

module.exports = nextConfig;

error

> next build

warn  - You have enabled experimental feature (runtime) in next.config.js.
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

info  - Linting and checking validity of types  
warn  - You are using an experimental edge runtime, the API might change.
warn  - You are using the experimental Edge Runtime with `experimental.runtime`.
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data ..ReferenceError: self is not defined
    at Object.<anonymous> (C:\Coding\Coding\Next.js\Çalışma\cloudflare\.next\server\pages\index.js:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.requirePage (C:\Coding\Coding\Next.js\Çalışma\cloudflare\node_modules\next\dist\server\require.js:88:12)
    at C:\Coding\Coding\Next.js\Çalışma\cloudflare\node_modules\next\dist\server\load-components.js:37:73
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

> Build error occurred
Error: Failed to collect page data for /
    at C:\Coding\Coding\Next.js\Çalışma\cloudflare\node_modules\next\dist\build\utils.js:959:15
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  type: 'Error'
}

index page

import { GetServerSideProps, NextPage } from "next";

interface Props {
  data: any;
}

const Home: NextPage<Props> = ({ data }) => {
  return (
    <ul>
      {data.map((element: any) => (
        <li key={element.id}>{element.title}</li>
      ))}
    </ul>
  );
};
export default Home;

export const getServerSideProps: GetServerSideProps = async (context) => {
  const response = await fetch("https://jsonplaceholder.typicode.com/todos");
  const data = await response.json();
  return {
    props: { data: data as any },
  };
};

@pksorensen
Copy link
Author

I dont understand how edge runtime can go GA with issue and either why this is closed.

@arielvieira
Copy link

@pksorensen I'm having the same you, but if I run the next.js app inside Linux (WSL) this doesn't happen.
@cantutar are you using windows as well?

So this seems related to next.js edge runtime not working properly on Windows, could someone help us confirm and have this issue re-open? @balazsorban44

@remorses
Copy link
Contributor

for anyone still having this problem, this error means that edge code is running on Nodejs, where self is not defined

you can work around this problem defining edge runtime for every page with the config export

@arielvieira
Copy link

@remorses I already have the runtime: 'experimental-edge' set in all pages and in next.config.js, but this only happen in Windows, while in Linux (WSL) it doesn't

@lolwuz
Copy link

lolwuz commented Feb 11, 2023

Same thing happens with me on windows on /pages/products/[id].tsx.

export const config = { runtime: "experimental-edge", };

Works fine on Ubuntu.

@arielvieira
Copy link

After upgrading to 13.1.7-canary.21 I'm able to run runtime: "experimental-edge" in windows 11

@gvatsov
Copy link

gvatsov commented Feb 20, 2023

13.1.7-canary.21

I can confirm the problem is resolved for me now. Thanks!

@cantutar
Copy link

@pksorensen I'm having the same you, but if I run the next.js app inside Linux (WSL) this doesn't happen. @cantutar are you using windows as well?

So this seems related to next.js edge runtime not working properly on Windows, could someone help us confirm and have this issue re-open? @balazsorban44

yes im using windows 10

@pksorensen
Copy link
Author

Yes, i am using windows 10 also. Have not worked on the project since i reported this issue, so can verifyi in a few days again that its still a problem.

@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 28, 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

No branches or pull requests

7 participants