redwoodjs / redwood

The App Framework for Startups
https://redwoodjs.com
MIT License
17.29k stars 992 forks source link

[Bug?]: prerender fails after 3.0.0 upgrade #6476

Open gilliardmacedo opened 2 years ago

gilliardmacedo commented 2 years ago

What's not working?

We created our project 8 months ago and maintain the generated NotFound route untouched so far. This is our single prerendered route. Recently we did the upgrade to Redwood 3 and I saw firstly this error.

After read the issue, I changed react and react-dom version from:

"react": "17.0.2",
"react-dom": "17.0.2",

to:

"react": "^17.0.2",
"react-dom": "^17.0.2",

and removed node_modules and yarn.lock.

Then I tried again:

$ yarn
$ yarn rw build

Result:

---------- Error rendering path "/404" ----------
TypeError: $ is not a function
    at Object.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/modules/es.object.keys.js:10:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/internals/object-keys.js:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/internals/object-define-properties.js:6:18)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/internals/object-create.js:3:30)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/internals/add-to-unscopables.js:2:14)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/modules/esnext.array.last-index.js:4:24)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/internals/regexp-sticky-helpers.js:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/modules/es.regexp.sticky.js:2:21)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/modules/es.regexp.dot-all.js:9:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/modules/es.regexp.constructor.js:7:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/modules/es.regexp.to-string.js:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/modules/es.symbol.description.js:11:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._compile (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/pirates/lib/index.js:141:7)
    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.<anonymous> (/Users/gilliardmvc/workspace-github/itlist-web/node_modules/core-js/internals/is-object.js:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)

I used the dry run just like the log suggests, but it succeeds:

$ yarn rw prerender --dry-run
::: Dry run, not writing changes :::
  ✔ Prerendering /404 -> web/dist/404.html
✨  Done in 11.01s.

For now I removed prerender directive from the route.

How do we reproduce the bug?

No response

What's your environment? (If it applies)

System:
    OS: macOS 12.6
    Shell: 5.1.4 - /usr/local/bin/bash
  Binaries:
    Node: 16.16.0 - /var/folders/cj/p55j1m7s3cn35z725ngtm3tm0000gn/T/yarn--1664565278635-0.9673860967942618/node
    Yarn: 1.22.19 - /var/folders/cj/p55j1m7s3cn35z725ngtm3tm0000gn/T/yarn--1664565278635-0.9673860967942618/yarn
  Databases:
    SQLite: 3.37.0 - /usr/bin/sqlite3
  Browsers:
    Chrome: 105.0.5195.125
    Firefox: 105.0.1
    Safari: 16.0
  npmPackages:
    @redwoodjs/core: ^3.0.1 => 3.0.3

Are you interested in working on this?

jtoar commented 2 years ago

Hey @gilliardmacedo, it seems like it's yarn rw build that's failing and not prerender specifically right? I understand that prerender needs build, but just want to make sure.

Looking at the error, it has to do with core-js. Is there any way you could provide a reproduction? Or narrow it down to what page isn't building, then provide the code for that? Does your project have any custom babel config?

I've seen this reported once before and the reason always seems to be different depending on the project, but we've solved it so if I could get more information I'm sure we could figure it out.

noire-munich commented 2 years ago

Thanks @gilliardmacedo for reaching out ;)

@jtoar I'm in @gilliardmacedo 's team actually, he'll correct me but I think we only had NotFoundPage with prerendering. Also here's some babel:

module.exports = {
  plugins: ['@emotion'],
}

Pretty thin! We are using chakra, but I don't know if it was setup with RW or before the command was shipped. Could be some conflicts somewhere. Gilliard has the lead on this, I'm merely backing up.

aloysb commented 2 years ago

Hey @jtoar

I have the same issue on a 3.2.0

Here's the error code:

---------- Error rendering path "/404" ----------
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/abr/Documents/perso/Projects/zef/node_modules/@simplewebauthn/browser/dist/bundle/index.js from /home/abr/Documents/perso/Projects/zef/node_modules/@redwoodjs/auth/dist/webAuthn/index.js not supported.
Instead change the require of /home/abr/Documents/perso/Projects/zef/node_modules/@simplewebauthn/browser/dist/bundle/index.js in /home/abr/Documents/perso/Projects/zef/node_modules/@redwoodjs/auth/dist/webAuthn/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.newLoader [as .js] (/home/abr/Documents/perso/Projects/zef/node_modules/pirates/lib/index.js:141:7)
    at Object.<anonymous> (/home/abr/Documents/perso/Projects/zef/node_modules/@redwoodjs/auth/dist/webAuthn/index.js:15:16)
    at Module._compile (/home/abr/Documents/perso/Projects/zef/node_modules/pirates/lib/index.js:136:24)
    at Object.newLoader [as .js] (/home/abr/Documents/perso/Projects/zef/node_modules/pirates/lib/index.js:141:7)
    at Object.<anonymous> (/home/abr/Documents/perso/Projects/zef/node_modules/@redwoodjs/auth/webAuthn/index.js:2:18)
    at Module._compile (/home/abr/Documents/perso/Projects/zef/node_modules/pirates/lib/index.js:136:24)
    at Object.newLoader [as .js] (/home/abr/Documents/perso/Projects/zef/node_modules/pirates/lib/index.js:141:7)
    at Object.<anonymous> (/home/abr/Documents/perso/Projects/zef/web/src/App.tsx:24:40)
    at Module._compile (/home/abr/Documents/perso/Projects/zef/node_modules/pirates/lib/index.js:136:24)
    at Object.newLoader [as .tsx] (/home/abr/Documents/perso/Projects/zef/node_modules/pirates/lib/index.js:141:7)
    at /home/abr/Documents/perso/Projects/zef/node_modules/@redwoodjs/prerender/dist/runPrerender.js:179:123
    at async runPrerender (/home/abr/Documents/perso/Projects/zef/node_modules/@redwoodjs/prerender/dist/runPrerender.js:179:7)
    at async Task.task (/home/abr/Documents/perso/Projects/zef/node_modules/@redwoodjs/cli/dist/commands/prerenderHandler.js:195:35)

Some more information: I'm using Chakra UI and I've set up the db-auth.

Keep up the good work RedwoodJS is a very exciting project, I'm building with it for the first time. I had a couple of issues, regarding auth and this one, but overall it's great. Thank you so much for your work!

starfish456 commented 1 year ago

Getting the same error, can't prerender any pages atm. I'm using rw 3.5.0, Chakra UI, and have dbAuth set-up.

---------- Error rendering path "/account" ---------- Error [ERR_REQUIRE_ESM]: require() of ES Module [...]/node_modules/@redwoodjs/auth/dist/webAuthn/index.js not supported.`

{ "data": { "redwood": { "version": "3.5.0", "currentUser": null, "prismaVersion": "4.5.0" } } }

ortegoncarlos commented 1 year ago

Hello guys (@jtoar), kind of same error here, first was"TypeError: $ is not a function" in core-js, so I added "resolutions": { "react": "17.0.2", "react-dom": "17.0.2", "core-js": "3.26.0" }, to the root package.json

after that If I run yarn rw prerender or yarn rw prerender --dry-run, did passed, but when built it fails, "no error showing",

i decided to Update libraries yarn update yarn upgrade --latest delete yarn.lock, node_modules in api, web and root. and re install using yarn install --force,

after digging around this subject, i found out this line could be the error:

https://github.com/redwoodjs/redwood/blob/ebc02201ac45d7206b05d3fa768691d339e70033/packages/cli/src/commands/buildHandler.js#L131-L134

just changing it to

cwd: rwjsPaths.base

makes it work,

so i think just running the yarn rw prerender from the base folder can fix the issue

dennemark commented 1 year ago

still no es module support with prerender :/ prerender does not use vite right?

Tobbe commented 1 year ago

@dennemark As of RW v5 prerender works with vite. ESM support is still ongoing work.