alphagov / govuk-prototype-kit

Rapidly create HTML prototypes of GOV.UK services
https://prototype-kit.service.gov.uk
MIT License
303 stars 236 forks source link

Kit version 13.14.0 will not run locally #2368

Closed lrdj closed 6 months ago

lrdj commented 9 months ago

Description of the issue

Kit will not run without internet connection. Issues error:

Error message:
Node.js v18.13.0
[nodemon] For missing modules try running `npm install`
Restarting kit...

You can manage your prototype at:
http://localhost:3000/manage-prototype

The Prototype Kit is now running at:
http://localhost:3000

/Users/ian/Sites/xd/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/ian/Sites/xd/node_modules/govuk-prototype-kit/lib/utils/index.js:273:81)
    at refreshPackageInfo (/Users/ian/Sites/xd/node_modules/govuk-prototype-kit/lib/plugins/packages.js:122:85)
    at async Promise.all (index 0)
    at async startPackageTracker (/Users/ian/Sites/xd/node_modules/govuk-prototype-kit/lib/plugins/packages.js:24:3)

Node.js v18.13.0
[nodemon] For missing modules try running `npm install`

Steps to reproduce the issue

  1. Disable internet (run as localhost)
  2. npm run dev

Actual vs expected behaviour

  1. With internet connection kit runs as expected
  2. With no internet Kit starts then ends execution and reports and error

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

andrewhercules commented 9 months ago

I'd like to add another instance of this issue, this time on a Windows laptop.

Description of the issue

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`

Steps to reproduce the issue

  1. Install a new instance of the prototype kit npx govuk-prototype-kit create test1

  2. Change to the directory of the prototype cd test1

  3. Run the prototype kit npm run dev

  4. See error message in terminal/console

Actual vs expected behaviour

Actual behaviour:

Expected behaviour:

Environment (where applicable)

Operating 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

benwatsonuk commented 9 months ago

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.

lrdj commented 9 months ago

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?

benwatsonuk commented 9 months ago

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.

lrdj commented 9 months ago

Righto Ben Sturgison has just pushed a new version. Haven't tested yet, but hopefully that's fixed it:-)

andrewhercules commented 9 months ago

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) 👍

36degrees commented 6 months ago

Looks like this was closed by #2370.