Open BenjaminWFox opened 3 years ago
Hi, those errors are not coming from Next.js directly as running npm init next-app
and then yarn dev
does not show those errors, are you adding custom configuration after creating your app with npm init next-app
or is a specific example being used?
@ijjk I'm able to replicate this issue with the following:
1.) yarn create next-app my-app
2.) Edit line 19-21 of pages/index.js
to be:
<p id="jest" className={styles.description}>
Get started by editing{' '}
<code className={styles.code}>pages/index.js</code>
</p>
3.) Run yarn dev
and open localhost:3000
4.) Result:
node -v: v14.17.2
npm -v: 6.14.13
yarn -v: 1.22.10
@mattcarlotta hmm can you confirm the Next.js version and react version being used with npm ls next react react-dom
? This warning should only be triggered when a global jest is set it seems per the react source here
@ijjk Here's the result:
npm ls next react react-dom
my-app@0.1.0 /home/m6d/Desktop/my-app
├── next@11.0.1
├── react@17.0.2
└── react-dom@17.0.2
Possibly related to the fact that any HTMLElement with an id
attribute is being interpolated as a global:
For example:
if (typeof window !== "undefined") {
setTimeout(() => {
console.log("window.jest", window.jest);
console.log("window.example", window.example);
}, 1000);
}
...etc
<p id="jest" className={styles.description}>
Get started by editing{" "}
<code className={styles.code}>pages/index.js</code>
</p>
<p id="example">Example</p>
Result:
If I just set window.jest
to "123", I also get the warning:
if (typeof window !== "undefined") {
window.jest = "123";
setTimeout(() => {
console.log("window.jest", window.jest);
}, 1000);
}
However, this doesn't affect the CRA
(no warnings):
Confirming this issue. I just run into that as well.
"react": "17.0.2",
"react-dom": "17.0.2",
"next": "12.3.1",
What version of Next.js are you using?
11.0.1, 11.0.2-canary.17
What version of Node.js are you using?
16.3.0
What browser are you using?
Chrome, Firefox, Safari
What operating system are you using?
MacOS
How are you deploying your application?
Locally
Describe the Bug
Creating a new project using
npm init next-app
and addingid="jest"
to any element on the default index page throws console errors.Expected Behavior
I do not expect test errors in non-test code.
To Reproduce
Create a new next app via
create-next-app
ornpm init next-app
Add
id="jest"
to any element on the homepage.