Upgrading the existing v13 prototypes to use import
Convert Node.js files in the Prototype Kit to use ECMAScript import, instead of CommonJS require, and set "type": "module" in package.json.
Why
New users familiar with using import to package their JavaScript code will find it confusing that the Kit uses the old method.
ECMAScript Modules are now the standard way to package JavaScript code, and Node.js and GOV.UK Frontend are both moving to prefer import over require. [1, 2]. Using ECMAScript modules will also let us use top-level awaits [3], which makes writing asynchronous scripts easier.
This change shouldn't affect users. Out of scope of this ticket is changing how JavaScript served to browsers by the kit is written.
Who needs to work on this
Developer
Who needs to review this
Developer
Done when
All Node.js files in the kit use ESM imports
The package.json for the kit sets the type to be ESM
What
Convert Node.js files in the Prototype Kit to use ECMAScript
import
, instead of CommonJSrequire
, and set"type": "module"
inpackage.json
.Why
New users familiar with using import to package their JavaScript code will find it confusing that the Kit uses the old method.
ECMAScript Modules are now the standard way to package JavaScript code, and Node.js and GOV.UK Frontend are both moving to prefer
import
overrequire
. [1, 2]. Using ECMAScript modules will also let us use top-levelawaits
[3], which makes writing asynchronous scripts easier.This change shouldn't affect users. Out of scope of this ticket is changing how JavaScript served to browsers by the kit is written.
Who needs to work on this
Developer
Who needs to review this
Developer
Done when