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

Bad next build when using new JSX transform & NODE_ENV=development #19001

Closed
AsherFoster opened this issue Nov 10, 2020 · 6 comments · Fixed by #20679
Closed

Bad next build when using new JSX transform & NODE_ENV=development #19001

AsherFoster opened this issue Nov 10, 2020 · 6 comments · Fixed by #20679
Assignees
Milestone

Comments

@AsherFoster
Copy link
Contributor

Bug report

Describe the bug

When creating a production build in development (Weird use case, I know, but I use this to test a compiled app with development settings), next appears to be confused about whether to use jsx or jsxDEV.

The app appears to have SSG rendered fine (I get a brief flash of content,) however when hydration is triggered on the client, the #__next div is emptied, and an infinite error loop occurs. Thousands of TypeError: Object(...) is not a function (Object(o.jsxDEV)(...) in source) errors appear in the console.

I don't know how next handles the JSX transform, but my guess is next build doesn't include jsxDEV on the client, somehow breaking the app.

Full trace
TypeError: Object(...) is not a function
    at r.default (_app-b6e6c2c671f93d19d381.js:1)
    at no (framework.4ed712e956e4440973f2.js:1)
    at ju (framework.4ed712e956e4440973f2.js:1)
    at xi (framework.4ed712e956e4440973f2.js:1)
    at Si (framework.4ed712e956e4440973f2.js:1)
    at ki (framework.4ed712e956e4440973f2.js:1)
    at pi (framework.4ed712e956e4440973f2.js:1)
    at ii (framework.4ed712e956e4440973f2.js:1)
    at Ki (framework.4ed712e956e4440973f2.js:1)
    at framework.4ed712e956e4440973f2.js:1

Compiled source:

r.default = function(e) {
  var r = e.Component
    , t = e.pageProps;

  // Error occurs here:

  return Object(o.jsxDEV)(r, function(e) {
    for (var r = 1; r < arguments.length; r++) {
      var t = null != arguments[r] ? arguments[r] : {};
      r % 2 ? c(Object(t), !0).forEach((function(r) {
          n(e, r, t[r])
        }
      )) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : c(Object(t)).forEach((function(r) {
          Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r))
        }
      ))
    }
    return e
  }({}, t), void 0, !1, {
    fileName: "[...]/jsxdev-repro/pages/_app.js",
    lineNumber: 4,
    columnNumber: 10
  }, this)
}

To Reproduce

Pretty straightforward to reproduce:

npx create-next-app jsxdev-repro
cd jsxdev-repro
NODE_ENV=development npm run build
npm start

Open site in a browser

Expected behavior

  • Client should correctly compile with jsx or jsxDEV
  • Hydration should not fail into a blank page state
  • Hydration should not enter an infinite loop

Screenshots

System information

  • macOS
  • Tested in firefox & chrome
  • Next 10.0.1
  • React(-dom) 17.0.1
  • Node 14.13

Additional context

Add any other context about the problem here.

@AsherFoster AsherFoster added the bug Issue was opened via the bug report template. label Nov 10, 2020
@Timer Timer added kind: bug and removed bug Issue was opened via the bug report template. labels Nov 11, 2020
@Timer
Copy link
Member

Timer commented Nov 11, 2020

It sounds like Next.js is accidentally allowing you to configure NODE_ENV=development when it should be forcing production for next build. We can look into this.

@Timer Timer added this to the iteration 13 milestone Nov 11, 2020
@Timer Timer added the point: 3 label Nov 11, 2020
@ChrisSargent
Copy link

I was having a similar issue resulting in the following error when building:

Error occurred prerendering page "/". Read more: https://err.sh/next.js/prerender-error
TypeError: ReactJSXRuntimeDev.jsxDEV is not a function

Setting NODE_ENV=production on the build script commands manually solved it for now.

@matthewdavidson
Copy link

I've encountered some related issues when using NODE_ENV=test in conjunction with next build.

Here is a reproduction repo: https://github.com/matthewdavidson/nextjs-nodenv-test-repro

Downgrading react 17 to 16 fixes @AsherFoster's original issue, but a separate issue exists with IE11 support:

Screenshot 2020-11-25 at 15 14 08

The generated output from a NODE_ENV=test next build is incompatible with IE11 (arrow functions are left intact etc).

@timneutkens timneutkens modified the milestones: iteration 13, iteration 14 Dec 1, 2020
@Timer Timer self-assigned this Dec 31, 2020
Timer added a commit to Timer/next.js that referenced this issue Jan 1, 2021
This PR fixes a bug where `next/babel` would accidentally enable development transforms for a production build (`next build`).

---

Fixes vercel#18929
Fixes vercel#19001
x-ref vercel#19046
Timer added a commit to Timer/next.js that referenced this issue Jan 1, 2021
This PR fixes a bug where `next/babel` would accidentally enable development transforms for a production build (`next build`).

---

Fixes vercel#18929
Fixes vercel#19001
x-ref vercel#19046
Timer added a commit to Timer/next.js that referenced this issue Jan 1, 2021
This PR fixes a bug where `next/babel` would accidentally enable development transforms for a production build (`next build`).

---

Fixes vercel#18929
Fixes vercel#19001
x-ref vercel#19046
@kodiakhq kodiakhq bot closed this as completed in #20679 Jan 2, 2021
kodiakhq bot pushed a commit that referenced this issue Jan 2, 2021
This PR fixes a bug where `next/babel` would accidentally enable development transforms for a production build (`next build`).

This is tested by the two updated unit tests (which removed a workaround for this bug, and one now properly enables dev transforms).

---

Fixes #18929
Fixes #19001
x-ref #19046
x-ref #17032
@anestesya
Copy link

I've encountered some related issues when using NODE_ENV=test in conjunction with next build.

Here is a reproduction repo: https://github.com/matthewdavidson/nextjs-nodenv-test-repro

Downgrading react 17 to 16 fixes @AsherFoster's original issue, but a separate issue exists with IE11 support:

Screenshot 2020-11-25 at 15 14 08

The generated output from a NODE_ENV=test next build is incompatible with IE11 (arrow functions are left intact etc).

worked for me, export NODE_ENV=test, before NODE_ENV=production

@TopHatMan
Copy link

This is broken again with latest react, react-dom , and nextjs. I downgraded to the ver in that repo and now its fixed.
I am forced to do NODE_ENV=production for build and start.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants