Node 16 Upgrade
Most of our repositories are currently using Node v8 or v12. As node v8’s support ended on 31st December 2019 and node v12’s support is scheduled to end on 30th April 2022, we’re going to start upgrading our repositories to node v16.
The upgrade will take place in two phases as follows:
Phase 1: Add Node 16 support:
The Arbi-BOM team will generate PRs to upgrade to phase 1 automatically. If you don’t see a PR in your repo that indicates ‘upgrade to node 16’, please reach out to #external-frontend-working-group slack channel. There are some differnces acros repos based on their Workflow files so they won’t all look exactly alike.
Arbi-BOM will do this: Apply node ci modernizer to add node 16 support in GitHub workflows. This workflow will do the following:
Add the matrix with Node versions 12, 14 and 16.
Sets NPM version 8.x.x
Upgrade node and npm version in Dockerfile as well (if exists).
If the package uses
node-sass
currently, replace it withsass
as node-sass is deprecated. Preferably, create a separate PR for this if it brings up a lot of changes.Run tests with Node 12, 14, and 16, and if any of the tests fail, fix them.
Preferably upgrade edx-owned dependencies to the Node 16 supported version. For some commonly used libraries, Node 16 supported versions are as follows:
Frontend-platform 1.15.1
Frontend-build 9.1.1
Paragon 19.6.0
Frontend-component-header 2.4.5
Frontend-component-footer 10.2.1
Update peer dependencies if possible.
Run
npm update
to update the dependencies, fix the conflicts and if any tests start to fail either fix them or ask owning the team for help. (optional)
IMPORTANT: While creating the PRs automatically using the cleanup job, the commit type was set to build but it should be feat so anyone working on the PR should update the type in PR title and commit message. (Sorry for this inconvenience).
Phase 2: Drop older node versions and fully migrate to Node 16
Drop Node 12 support:
Remove node 12 and 14 from node versions list in strategy matrix for ci workflow.
Switch node version from 12 to 16 in release workflow. For example, here is how node versions are specified in a workflow file: https://github.com/openedx/frontend-app-profile/blob/master/.github/workflows/ci.yml#L17
Update node version in .nvmrc file if exists to something like
v16
. (for local dev with nvm only)ensure your .nvmrc has node16 in it or add one. This file is not used in build/deploy pipelines, it’s
just for your local dev comfort.
cd to MFE dir
Install nvm if not already
nvm use
This will change your node version to node16. It may ask you to install node16 first.
Verify node version (v16.y.z) and npm versions (v8.y.z)
Delete node_modules/ and package-lock files so they can be regenerated by the new npm version
Make sure the package-lock.json has
"lockfileVersion": 2
. If it has"lockfileVersion": 1
then runnpm install
with Node 16 and npm 8 activated via nvm.Once the PR is ready, request a review from owning team. They’ll review the changes, test on their end and deploy.
(we’ll consider adding a modernizer to automate this phase as well but as of now it’s going to be a manual step taken by the owning team).
If applicable, please update the status in this sheet as well Node 16 upgrade status tracking
Steps to deploy an MFE on Node 16:
The MFEs will still be deployed using node12 in the gocd pipeline at this point, so please do this step once you have updated your Github workflows file, not too long after you merge the prior PR.
IMPORTANT: Ensure that MFE already has support for Node 16 and the package-lock.json has "lockfileVersion": 2
. If it has "lockfileVersion": 1
then run npm install
with Node 16 and npm 8 activated via nvm and push or go through the open PRs and you might find one automated PR already created by the bot for this purpose.
Set the ‘use_node_16’ flag to true in frontend-generator-inputs.yaml for target MFE. For instance, this PR was created for Frontend-app-authn https://github.com/edx/edx-internal/pull/6393 .
Go to GoCD, trigger the stage pipeline of target MFE and once MFE is deployed on stage, test it.
Once testing is done on stage environment, deploy on production and monitor the changes.
Prioritized Order for the upgrade:
Frontend libraries on which most of the frontend repos are dependent like frontend-build, frontend-enterprise, paragon, eslint-config etc.
List of repos blocking the browserslist work mentioned here Node 16 Upgrade & Shared Browserslist Config.
Remaining repositories.
Note: All the edx-based dependencies for the target repository should be preferably upgraded to node 16 prior to upgrading that repository.
Preferred approach for developers:
Developers should install nvm on their machines to switch between node versions during the upgrade process as some repos will be on node 12 and some will be on node 16 during the upgrade period.
Troubleshooting/tips during node upgrades
A few issues we have run into and potential solutions, example PRs follow.
node15 has started generating failures instead of warnings on unhandled promise rejections. You may find tests are going to fail for what used to be warnings before. e.g.,, this PR fixes a few warnings that failed tests with node16: https://github.com/openedx/frontend-app-enterprise-public-catalog/pull/199
if you happen to need to upgrade jest (you may very well need to, to v25) then note that your tests may start failing if they use. See this for details: https://github.com/openedx/paragon/pull/1068/files#r816561658
Jest v25 uses jsdom v15 (link) and all the tests related to focus started to fail due to the changes introduced in jsdom v15 (link). You may need to apply a fix to use attachTo in order to fix this issue following these references link1, link2. Reference PR
if you upgrade to a newer edx/eslint-config version (which is now using node16), you may also need to fix eslint issues such as this reference PR
Helpful local testing notes for testing out enterprise repos against node 16
To test enterprise MFEs against frontend-enterprise changes locally
Install
nvm
locally (you can use other node manages too this is just what I use)Sync this branch of frontend-enterprise with Adam’s fixes: https://github.com/openedx/frontend-enterprise/pull/250
Start completely clean, remove node_modules/, package-lock file (it will all need to be regenerated)
update .nvmrc file to v16 if not already
nvm use
(nvm will ask to install node16 if not already on your system)Verify node is now 16 and npm is v8
node -v; npm -v
npm run clean; npm run setup; npm run build
All set with frontend-enterprise prep
MFE
For MFE: keep what you have, do not upgrade node:
Ensure node version by
node -v
andnpm -v
is what you used to have.Create/update module.config.js file with the necessary changes such as this (for learner portal)
{ moduleName: '@edx/frontend-enterprise-catalog-search', dir: '../frontend-enterprise/packages/catalog-search', dist: 'src' },
{ moduleName: '@edx/frontend-enterprise-utils', dir: '../frontend-enterprise/packages/utils', dist: 'src' },
Note: using
dist: 'src'
mean you will get hot reload without having to rebuild frontend-enterprise all the timeStart app. If already running, you first need to ctrl+c to pick up the module.config changes
Test the app!
There you go, this is what I think needs to be done. I will be doing this myself, but this is for adventurous souls to explore as they wish!