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

Upgrading nextjs to 12.3 #1103

Closed
wants to merge 22 commits into from
Closed

Conversation

wonjun-opensource
Copy link
Contributor

@wonjun-opensource wonjun-opensource commented Sep 18, 2022

Issue #894

Upgrades nextjs to 12.3, and React is now at 18.2.

  • OUSD site is fully rendering, and Swap & Wrapping work as expected on the local dev environment.

  • Module alias now moves to jsconfig.json out of package.json. Nextjs handles it without the need for "babel-plugin-module-resolver" in package.json.

  • Nextjs 12 disabled css loading from a url by default. url import is an experimental feature we can enable, if needed, https://nextjs.org/docs/api-reference/next.config.js/url-imports

  • TODO: Sentry does not run on the local dev environment, so this needs to be tested on staging.

  • New code changes trigger the following warnings in Terminal,

Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc" https://nextjs.org/docs/messages/swc-disabled

=> SWC that comes with nextjs 12.3 does not handle "babel" ordering we have in package.json, specifically "babel-plugin-fbt", "babel-plugin-fbt-runtime", which needs to do the transforms before other transforms beat to the Babel AST, so I moved "presets" and "plugins" to .babelrc, and that disables SWC for now.

If we want to re-enable SWC, we may need to wait for SWC to add better support for it, or handle it with something like this they suggested, https://facebook.github.io/fbt/docs/getting_started_on_web/#babel-plugin-ordering-caveat.

fbt-runtime is no longer supported, so we should consider changing it to using fbt or next-i18next, which seems more compatible with nextjs, possibly without the same problem fbt-runtime gives.

warn  - ./node_modules/@myetherwallet/mewconnect-web-client/src/connectClient/config.js
Should not import the named export 'version' (imported as 'packageJSON') from default-exporting module (only default export is available soon)

=> @myetherwallet/mewconnect-web-client is no longer supported. We may be able to suppress this type of warning. I left it as it is now.

./node_modules/@0x/utils/node_modules/ethers/dist/ethers.min.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

=> We either need to suppress this type of warning or wait for the package to be updated. The latest version still triggers this warning, so I kept the existing version.

@wonjun-opensource wonjun-opensource self-assigned this Sep 18, 2022
…abled css loading from a url by default. url import is an experimental feature we can enable, if needed, https://nextjs.org/docs/api-reference/next.config.js/url-imports
@wonjun-opensource wonjun-opensource marked this pull request as ready for review September 18, 2022 23:21
@sparrowDom
Copy link
Member

@wonjun-opensource thank you for this awesome work and in depth research in to things. Wanted to deploy it to staging to test out sentry but it has failed:

Already have image (with digest): gcr.io/google.com/cloudsdktool/cloud-sdk
Services to deploy:

descriptor:                  [/workspace/dapp/staging.app.yaml]
source:                      [/workspace/dapp]
target project:              [origin-214503]
target service:              [ousd-staging]
target version:              [20220919t091637]
target url:                  [https://ousd-staging-dot-origin-214503.appspot.com]
target service account:      [App Engine default service account]


Beginning deployment of service [ousd-staging]...
╔════════════════════════════════════════════════════════════╗
╠═ Uploading 8 files to Google Cloud Storage                ═╣
╚════════════════════════════════════════════════════════════╝
File upload done.
Updating service [ousd-staging] (this may take several minutes)...
................................done.
----------------------------- REMOTE BUILD OUTPUT ------------------------------
starting build "5625448c-27f7-4df4-b7fc-dc37c852f942"

FETCHSOURCE
BUILD
Starting Step #0 - "fetcher"
Step #0 - "fetcher": Already have image (with digest): gcr.io/cloud-builders/gcs-fetcher
Step #0 - "fetcher": Fetching manifest gs://staging.origin-214503.appspot.com/ae/99a48d32-25c2-4a1c-80b1-d5b0bb00d9ca/manifest.json.
Step #0 - "fetcher": Processing 453 files.
Step #0 - "fetcher": ******************************************************
Step #0 - "fetcher": Status:                      SUCCESS
Step #0 - "fetcher": Started:                     2022-09-19T09:17:03Z
Step #0 - "fetcher": Completed:                   2022-09-19T09:17:05Z
Step #0 - "fetcher": Requested workers:    200
Step #0 - "fetcher": Actual workers:       200
Step #0 - "fetcher": Total files:          453
Step #0 - "fetcher": Total retries:          0
Step #0 - "fetcher": GCS timeouts:           0
Step #0 - "fetcher": MiB downloaded:         8.95 MiB
Step #0 - "fetcher": MiB/s throughput:       6.59 MiB/s
Step #0 - "fetcher": Time for manifest:    470.34 ms
Step #0 - "fetcher": Total time:             1.83 s
Step #0 - "fetcher": ******************************************************
Finished Step #0 - "fetcher"
Starting Step #1
Step #1: Pulling image: gcr.io/gcp-runtimes/nodejs/gen-dockerfile@sha256:8e2b8eef87fae1bc4b80206cc84139a52973433daafef5ba30ae84f2f85d01b6
Step #1: gcr.io/gcp-runtimes/nodejs/gen-dockerfile@sha256:8e2b8eef87fae1bc4b80206cc84139a52973433daafef5ba30ae84f2f85d01b6: Pulling from gcp-runtimes/nodejs/gen-dockerfile
Step #1: Digest: sha256:8e2b8eef87fae1bc4b80206cc84139a52973433daafef5ba30ae84f2f85d01b6
Step #1: Status: Downloaded newer image for gcr.io/gcp-runtimes/nodejs/gen-dockerfile@sha256:8e2b8eef87fae1bc4b80206cc84139a52973433daafef5ba30ae84f2f85d01b6
Step #1: gcr.io/gcp-runtimes/nodejs/gen-dockerfile@sha256:8e2b8eef87fae1bc4b80206cc84139a52973433daafef5ba30ae84f2f85d01b6
Step #1: Checking for Node.js.
Step #1: WARNING:  Your package.json does not specify a supported Node.js version.  Please pin your application to a major version of the Node.js runtime.  To learn more, visit https://cloud.google.com/appengine/docs/flexible/nodejs/runtime
Finished Step #1
Starting Step #2
Step #2: Already have image (with digest): gcr.io/kaniko-project/executor@sha256:f87c11770a4d3ed33436508d206c584812cd656e6ed08eda1cff5c1ee44f5870
Step #2: INFO[0000] Removing ignored files from build context: [node_modules .dockerignore Dockerfile npm-debug.log yarn-error.log .git .hg .svn staging.app.yaml] 
Step #2: INFO[0000] Downloading base image gcr.io/google-appengine/nodejs@sha256:1b9d17453000c2c6c819b055688821db3deaa2dfa7fb4e73606c8788f6c9e29a
Step #2: INFO[0015] Taking snapshot of full filesystem...
Step #2: INFO[0022] Using files from context: [/workspace]       
Step #2: INFO[0022] COPY . /app/                                 
Step #2: INFO[0022] RUN NODE_ENV=development yarn install ||   ((if [ -f yarn-error.log ]; then       cat yarn-error.log;     fi) && false) 
Step #2: INFO[0022] cmd: /bin/sh                                 
Step #2: INFO[0022] args: [-c NODE_ENV=development yarn install ||   ((if [ -f yarn-error.log ]; then       cat yarn-error.log;     fi) && false)] 
Step #2: yarn install v1.22.18
Step #2: [1/4] Resolving packages...
Step #2: [2/4] Fetching packages...
Step #2: warning mini-css-extract-plugin@0.4.3: Invalid bin field for "mini-css-extract-plugin".
Step #2: error next@12.3.0: The engine "node" is incompatible with this module. Expected version ">=12.22.0". Got "12.19.0"
Step #2: error Found incompatible module.
Step #2: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Step #2: error building image: error building stage: waiting for process to exit: exit status 1
Finished Step #2
ERROR
ERROR: build step 2 "gcr.io/kaniko-project/executor@sha256:f87c11770a4d3ed33436508d206c584812cd656e6ed08eda1cff5c1ee44f5870" failed: step exited with non-zero status: 1
--------------------------------------------------------------------------------
Updating service [ousd-staging] (this may take several minutes)...
.....failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build 5625448c-27f7-4df4-b7fc-dc37c852f942 status: FAILURE
Build error details: Build error details not available.
Full build logs: https://console.cloud.google.com/cloud-build/builds/5625448c-27f7-4df4-b7fc-dc37c852f942?project=715174050235

I need to look into that. And like you point out we still need to solve the FBT issue probably by migrating to something better supported.

@wonjun-opensource
Copy link
Contributor Author

wonjun-opensource commented Sep 20, 2022

@sparrowDom Thank you for the review,

It says NextJs minimum is 12.22.0, so I updated README.

[Edit]
I pushed my last commit to hopefully address

Step #1: WARNING:  Your package.json does not specify a supported Node.js version.  Please pin your application to a major version of the Node.js runtime.  To learn more, visit https://cloud.google.com/appengine/docs/flexible/nodejs/runtime
Finished Step #1
...
Step #2: error next@12.3.0: The engine "node" is incompatible with this module. Expected version ">=12.22.0". Got "12.19.0"

by adding

  "engines": {
    "node": "14.x",
    "npm": "6.x"
  },

in package.json

Could you try staging build again when you get a chance?

@sparrowDom
Copy link
Member

Hey sorry for super late reply. Failed when tried to deploy with:

Step #3 - "Generate abis adn copy to dapp folder": $ mkdir -p ../dapp/abis && cp artifacts/contracts/interfaces/IVault.sol/IVault.json ../dapp/abis/IVault.json && cp artifacts/contracts/liquidity/LiquidityReward.sol/LiquidityReward.json ../dapp/abis/LiquidityReward.json && cp artifacts/contracts/interfaces/uniswap/IUniswapV2Pair.sol/IUniswapV2Pair.json ../dapp/abis/IUniswapV2Pair.json && cp artifacts/contracts/staking/SingleAssetStaking.sol/SingleAssetStaking.json ../dapp/abis/SingleAssetStaking.json && cp artifacts/contracts/compensation/CompensationClaims.sol/CompensationClaims.json ../dapp/abis/CompensationClaims.json && cp artifacts/contracts/flipper/Flipper.sol/Flipper.json ../dapp/abis/Flipper.json && cp artifacts/contracts/flipper/Flipper.sol/Flipper.json ../dapp/abis/Flipper.json
Step #3 - "Generate abis adn copy to dapp folder": Done in 60.63s.
Finished Step #3 - "Generate abis adn copy to dapp folder"
Starting Step #4 - "Install dapp dependencies"
Step #4 - "Install dapp dependencies": Already have image: node:16
Step #4 - "Install dapp dependencies": yarn install v1.22.19
Step #4 - "Install dapp dependencies": [1/5] Validating package.json...
Step #4 - "Install dapp dependencies": error origin-dollar-dapp@0.1.0: The engine "node" is incompatible with this module. Expected version "14.x". Got "16.17.1"
Step #4 - "Install dapp dependencies": error Found incompatible module.
Step #4 - "Install dapp dependencies": info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Finished Step #4 - "Install dapp dependencies"
ERROR
ERROR: build step 4 "node:16" failed: step exit

Then I've changed it to:

 "engines": {
    "node": "16.x",
    "npm": "6.x"
  },

and deploy also failed with:

Step #5 - "Deploy the app": Step #1: Status: Downloaded newer image for gcr.io/gcp-runtimes/nodejs/gen-dockerfile@sha256:8e2b8eef87fae1bc4b80206cc84139a52973433daafef5ba30ae84f2f85d01b6
Step #5 - "Deploy the app": Step #1: gcr.io/gcp-runtimes/nodejs/gen-dockerfile@sha256:8e2b8eef87fae1bc4b80206cc84139a52973433daafef5ba30ae84f2f85d01b6
Step #5 - "Deploy the app": Step #1: Checking for Node.js.
Step #5 - "Deploy the app": Finished Step #1
Step #5 - "Deploy the app": Starting Step #2
Step #5 - "Deploy the app": Step #2: Already have image (with digest): gcr.io/kaniko-project/executor@sha256:f87c11770a4d3ed33436508d206c584812cd656e6ed08eda1cff5c1ee44f5870
Step #5 - "Deploy the app": Step #2: INFO[0000] Removing ignored files from build context: [node_modules .dockerignore Dockerfile npm-debug.log yarn-error.log .git .hg .svn staging.app.yaml] 
Step #5 - "Deploy the app": Step #2: INFO[0000] Downloading base image gcr.io/google-appengine/nodejs@sha256:1b9d17453000c2c6c819b055688821db3deaa2dfa7fb4e73606c8788f6c9e29a
Step #5 - "Deploy the app": Step #2: INFO[0017] Taking snapshot of full filesystem...
Step #5 - "Deploy the app": Step #2: INFO[0024] Using files from context: [/workspace]       
Step #5 - "Deploy the app": Step #2: INFO[0024] COPY . /app/                                 
Step #5 - "Deploy the app": Step #2: INFO[0024] RUN NODE_ENV=development yarn install ||   ((if [ -f yarn-error.log ]; then       cat yarn-error.log;     fi) && false) 
Step #5 - "Deploy the app": Step #2: INFO[0024] cmd: /bin/sh                                 
Step #5 - "Deploy the app": Step #2: INFO[0024] args: [-c NODE_ENV=development yarn install ||   ((if [ -f yarn-error.log ]; then       cat yarn-error.log;     fi) && false)] 
Step #5 - "Deploy the app": Step #2: yarn install v1.22.18
Step #5 - "Deploy the app": Step #2: [1/5] Validating package.json...
Step #5 - "Deploy the app": Step #2: error origin-dollar-dapp@0.1.0: The engine "node" is incompatible with this module. Expected version "16.x". Got "12.19.0"
Step #5 - "Deploy the app": Step #2: error Found incompatible module.
Step #5 - "Deploy the app": Step #2: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Step #5 - "Deploy the app": Step #2: error building image: error building stage: waiting for process to exit: exit status 1
Step #5 - "Deploy the app": Finished Step #2
Step #5 - "Deploy the app": ERROR
Step #5 - "Deploy the app": ERROR: build step 2 "gcr.io/kaniko-project/executor@sha256:f87c11770a4d3ed33436508d206c584812cd656e6ed08eda1cff5c1ee44f5870" failed: step exited with non-zero status: 1
Step #5 - "Deploy the app": --------------------------------------------------------------------------------
Step #5 - "Deploy the app": Updating service [ousd-staging] (this may take several minutes)...
Step #5 - "Deploy the app": ...................................failed.
Step #5 - "Deploy the app": ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build 6f481d7b-405d-4773-b6c2-b9284f3dc3e7 status: FAILURE
Step #5 - "Deploy the app": Build error details: Build error details not available.
Step #5 - "Deploy the app": Full build logs: https://console.cloud.google.com/cloud-build/builds/6f481d7b-405d-4773-b6c2-b9284f3dc3e7?project=715174050235
Finished Step #5 - "Deploy the app"

@wonjun-opensource
Copy link
Contributor Author

@sparrowDom Thanks for trying that. Sorry about the late reply, too. I see in both error messages you shared, it indicates that node 14.x was not installed successfully. I pushed a change setting "node": ">= 14.9" based on GoogleCloudPlatform/nodejs-docker#214 (comment) I hope that fixes the error you saw.

Contracts Fork Tests fail as it is also failing in the master. Changes here are limited to /dapp folder only.

@franckc
Copy link

franckc commented Jan 20, 2023

@sparrowDom What are your thoughts? Shall we move forward with this upgrade? Looks like the Contracts Fork Tests failed - so we should check on that before merging.

@sparrowDom
Copy link
Member

yeah the contract fork test failing isn't relevant and/or a problem.

I have added a build github workflow that tests if the production build succeeds. Testing the development speed (which was one of the main highlights of next12+) the results are pretty disappointing on my M1 Mac.

Nextjs v10 from initial startup in console to first page render takes ~32 seconds. NextJs v12 takes 45 seconds and NextJs v13 takes 42. It could be the issue is because of Mac silicone.

@shahthepro you have an intel mac right? When convenient could you maybe benchmark the speed of first page render comparing NextJs on master ( v10 ) and the one in this branch ( v13 ).

If there are no speed gains we will just close the PR.

@sparrowDom
Copy link
Member

Also NextJs 13 requires node v14+ and Google GAE flexible environment has the node fixed to v12. There is a custom environment with a Docker workaround, but I haven't managed to get that working yet. And will stop with efforts until we get a clear metric of this NextJs being faster on at least some machines.

@sparrowDom
Copy link
Member

I think we can table this one for now

@sparrowDom sparrowDom closed this Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants