|
| 1 | +--- |
| 2 | +title: NodeJS |
| 3 | +sidebar_label: NodeJS versions |
| 4 | +description: Information about how NodeJS supported versions correlate with Moodle releases and the policy controlling it. |
| 5 | +tags: |
| 6 | + - Requirements |
| 7 | + - Support |
| 8 | + - Releases |
| 9 | + - NodeJS |
| 10 | +--- |
| 11 | + |
| 12 | +New LTS NodeJS versions are [released every 12 months](https://github.com/nodejs/release#release-schedule) and supported for three years. Moodle tries to ensure a compromise between support and churn by ensuring that the version of NodeJS in use is supported at all times. |
| 13 | + |
| 14 | +## Policy statement |
| 15 | + |
| 16 | +### NodeJS |
| 17 | + |
| 18 | +<Since versions={["3.1"]} issueNumber="MDL-63346" /> |
| 19 | + |
| 20 | +1. This policy will be applied to _all_ supported branches, including stable and security-only releases. |
| 21 | +1. This policy does not require that any tool be updated, unless strictly needed by nodejs/npm or its own dependencies/changes |
| 22 | +1. It won't include npm audit changes either. Those are handled separately. |
| 23 | +1. Normally, only changes to `.nvmrc` and `package.json` will happen. |
| 24 | +1. Changes to project dependencies should be handled in a separate issue. |
| 25 | + |
| 26 | +### Project Dependencies |
| 27 | + |
| 28 | +<Since versions={["5.0"]} issueNumber="IDEA-168" /> |
| 29 | + |
| 30 | + 1. To avoid impact to the community, dependency updates which impact built output should be kept to a minimum. |
| 31 | + 1. Dependency updates should be backported to the first Major release in a Series, for example Moodle 5.0. |
| 32 | + |
| 33 | +## Upgrade guidelines |
| 34 | + |
| 35 | +### NodeJS |
| 36 | + |
| 37 | +To update the NodeJS version required, the following approach is typically recommended: |
| 38 | + |
| 39 | +1. Update the `.nvmrc` file to reflect the `lts/[name]` of the new LTS version |
| 40 | +1. Update the `package.json` to set the `engines` for the new restiction in the format: `>= [new version] < [next version]`, for example: |
| 41 | + |
| 42 | + ```json |
| 43 | + "engines": { |
| 44 | + "node": ">=20.11.0 <21" |
| 45 | + } |
| 46 | + ``` |
| 47 | + |
| 48 | +1. Install the new NodeJS version: |
| 49 | + |
| 50 | + ```sh |
| 51 | + nvm install && nvm use |
| 52 | + ``` |
| 53 | + |
| 54 | +1. Update the NodeJS dependencies with the new version of NodeJS: |
| 55 | + |
| 56 | + ```sh |
| 57 | + rm -rf node_modules |
| 58 | + npm install |
| 59 | + ``` |
| 60 | + |
| 61 | +1. Verify the update: |
| 62 | + |
| 63 | + ```sh |
| 64 | + npx grunt |
| 65 | + npx grunt jsdoc |
| 66 | + ``` |
| 67 | + |
| 68 | +In most situations there will be no issues here and changes can be committed and backported to all stable and security-supported branches. |
| 69 | + |
| 70 | +#### Troubleshooting |
| 71 | + |
| 72 | +Where a project dependency is no longer supported due to the new version of NodeJS, it may be necessary to upgrade the dependency. |
| 73 | + |
| 74 | +### Project dependencies |
| 75 | + |
| 76 | +The following tooling may be useful for the purposes of updating the project dependencies: |
| 77 | + |
| 78 | +- `npm outdated` |
| 79 | +- `npm audit` |
0 commit comments