-
Notifications
You must be signed in to change notification settings - Fork 246
Description
Description of the issue
I think the introduction of npm-shrinkwrap.json in last version is causing (not sure if always the case or there was a version conflict that caused it) the dependencies of the govuk-prototype-kit to only be installed in /node_modules/govuk-prototype-kit/node_modules/ where as they previously got hoisted up to /node_modules/
this can be an issue if someone had some code in their prototype that was trying to require() one of those dependencies - with no direct dependency
if they did an npm install before updating, then locally the prototype might run ok, but when pushed and a clean install is done, the dependencies aren't hoisted and it can fail with an error making it hard to debug
Steps to reproduce the issue
- created an example "vulnerable" prototype on v13.16.2 of prototype kit which imports express
https://github.com/oscarduignan/2025-07-01-prototype/blob/main/app/routes.js#L6 - if you npm install and npm run dev that it will startup fine
- npm install govuk-prototype-kit@13.17.0
- if you run npm run dev again it will start
- remove the node_modules folder and npm install again (like if you pushed it to heroku or somewhere to deploy)
- if you run npm run dev now it will fail with error about missing express

to see the cause is npm-shrinkwrap.json
- cp node_modules/govuk-prototype-kit ../govuk-prototype-kit
- rm -rf ../govuk-prototype-kit/node_modules ../govuk-prototype-kit/npm-shrinkwrap.json
- rm -rf node_modules
- npm install ../govuk-prototype-kit
- npm run dev will start ok
you can see the difference in hoisting of dependencies by running "ls node_modules" on the different versions, and see how with shrinkwrap they aren't hoisted to top level node_modules
Actual vs expected behaviour
npm-shrinkwrap.json is probably useful, but it's quite a big change and the errors from this can be hard to debug
in the example, really the prototype we saw this on didn't need to import express, but it also wasn't hurting anything, and it is hard for maintainer to tell if it's ok to remove
might be worth a PSA in x-gov to make people aware of the risk of breakage when updating / considering if any mitigations that can be done (I'm not familiar enough with shrinkwrap to know if there are any ways to work around this)
Environment (where applicable)
N/A I think
- Node version: (not sure if it's impactful) v20.18.0
- Operating system: mac
- Browser:
- Browser version:
- GOV.UK Prototype Kit version: 13.17.0 (where npm-shrinkwrap.json was added to package.json file list)