Closed lrdj closed 6 months ago
I'd like to add another instance of this issue, this time on a Windows laptop.
Version 13.14.0 of the prototype kit will not run after entering npm run dev
. It generates a TypeError and localhost:3000
shows a blank page.
Below is an example of the error message:
$ npm run dev
> dev
> govuk-prototype-kit dev
GOV.UK Prototype Kit 13.14.0
starting...
You can manage your prototype at:
http://localhost:3000/manage-prototype
The Prototype Kit is now running at:
http://localhost:3000
C:\Users\ahercules\Desktop\prototypes\test2\node_modules\govuk-prototype-kit\lib\utils\index.js:273
const [, latestMajor, latestMinor, latestPatch, latestSuffix] = latestVersion.match(matcher)
^
TypeError: Cannot read properties of undefined (reading 'match')
at hasNewVersion (C:\Users\ahercules\Desktop\prototypes\test2\node_modules\govuk-prototype-kit\lib\utils\index.js:273:81)
at refreshPackageInfo (C:\Users\ahercules\Desktop\prototypes\test2\node_modules\govuk-prototype-kit\lib\plugins\packages.js:122:85)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 1)
at async startPackageTracker (C:\Users\ahercules\Desktop\prototypes\test2\node_modules\govuk-prototype-kit\lib\plugins\packages.js:24:3)
Node.js v18.12.1
[nodemon] For missing modules try running `npm install`
Install a new instance of the prototype kit
npx govuk-prototype-kit create test1
Change to the directory of the prototype
cd test1
Run the prototype kit
npm run dev
See error message in terminal/console
Actual behaviour:
npm run dev
generates a TypeError and prints and error in the terminallocalhost:3000
shows a blank page Expected behaviour:
npm run dev
does not generate an errorlocalhost:3000
shows the initial prototype kit UIOperating system: Windows 10 Enterprise Version 21H2 Browser: Chrome 118.0.5993.71 (Official Build) (32-bit) Node: 18.12.1 NPM: 8.19.2 Prototype kit: 13.14.0
I have just run the latest kit using the same Node version and it looks as though the issue is triggered when an outbound connection is prevented.
With outbound internet connection:
`benwatson@Bens-MacBook-Pro testBen % nvm use 18.12.1
Now using node v18.12.1 (npm v8.19.2)
benwatson@Bens-MacBook-Pro testBen % npm run dev
> dev
> govuk-prototype-kit dev
GOV.UK Prototype Kit 13.14.0
starting...
You can manage your prototype at:
http://localhost:3000/manage-prototype
The Prototype Kit is now running at:
http://localhost:3000`
Without outbound connection:
`benwatson@Bens-MacBook-Pro testBen % npm run dev
> dev
> govuk-prototype-kit dev
GOV.UK Prototype Kit 13.14.0
starting...
You can manage your prototype at:
http://localhost:3000/manage-prototype
The Prototype Kit is now running at:
http://localhost:3000
/Users/benwatson/Sites/clients/FCA/testBen/node_modules/govuk-prototype-kit/lib/utils/index.js:273
const [, latestMajor, latestMinor, latestPatch, latestSuffix] = latestVersion.match(matcher)
^
TypeError: Cannot read properties of undefined (reading 'match')
at hasNewVersion (/Users/benwatson/Sites/clients/FCA/testBen/node_modules/govuk-prototype-kit/lib/utils/index.js:273:81)
at refreshPackageInfo (/Users/benwatson/Sites/clients/FCA/testBen/node_modules/govuk-prototype-kit/lib/plugins/packages.js:122:85)
at async Promise.all (index 0)
at async startPackageTracker (/Users/benwatson/Sites/clients/FCA/testBen/node_modules/govuk-prototype-kit/lib/plugins/packages.js:24:3)
Node.js v18.12.1
[nodemon] For missing modules try running `npm install`
`
I believe the culprit is the following piece of code:
`async function requestRegistryInfo (packageName) {
const timer = startPerformanceTimer()
try {
const registryInfoUrl = `https://registry.npmjs.org/${encodeURIComponent(packageName)}`
verboseLog(`looking up ${registryInfoUrl}`)
const registryInfo = await requestHttpsJson(registryInfoUrl)
verboseLog(`retrieved ${registryInfoUrl}`)
endPerformanceTimer('lookupPackageInfo (success)', timer)
return registryInfo
} catch (e) {
endPerformanceTimer('lookupPackageInfo (failure)', timer)
verboseLog('ignoring error', e.message)
return undefined
}
}`
On line 38 of https://github.com/alphagov/govuk-prototype-kit/blob/main/lib/plugins/packages.js there appears to be a requirement for an outbound connection to reach https://registry.npmjs.org/
This appears to be called in https://github.com/alphagov/govuk-prototype-kit/blob/main/lib/utils/index.js which introduced the 'hasNewVersion' function on line 270 (https://github.com/alphagov/govuk-prototype-kit/commit/f38c2a236134a5851740a910ee023ee655b3f228)
Hopefully that helps in some way.
Wow @benwatsonuk that's a pretty darn specific report:-) Can you suggest a modification to that function which would make the call non-blocking or optional? Guessing it's important the kit's ui notifies of updates, but not at the cost of killing the app... is this the kind if thing a non-coder like me might comment out?
Wow @benwatsonuk that's a pretty darn specific report:-) Can you suggest a modification to that function which would make the call non-blocking or optional? Guessing it's important the kit's ui notifies of updates, but not at the cost of killing the app... is this the kind if thing a non-coder like me might comment out?
It looks as though it will need a graceful way of exiting if the repository can't be reached. I'll try and raise a pull request next week.
I suppose for now you could try to comment out lines 272 - 287 in https://github.com/alphagov/govuk-prototype-kit/blob/main/lib/utils/index.js in your project's node_modules/govuk-prototype-kit/ instance. This is obviously a hack but might allow you develop locally for a while until there is a suitable fix.
Righto Ben Sturgison has just pushed a new version. Haven't tested yet, but hopefully that's fixed it:-)
I've just tested the latest version 13.15.0
and it runs with no internet connection (or restricted connections due to a corporate firewall) 👍
Looks like this was closed by #2370.
Description of the issue
Kit will not run without internet connection. Issues error:
Steps to reproduce the issue
Actual vs expected behaviour
Environment (where applicable)
OSX 12.6.9 Safari 17.1 npm -v 8.19.3 node -v v18.13.0 kit version 13.14.0