When you create a new starter app project following the Quick Start instructions with v2.3.0, the startup of the local dev server fails with an error:
Uncaught exception: TypeError: (0 , _crypto.randomUUID) is not a function
at /Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/pwa-kit-dev/ssr/server/build-dev-server.js:105:53
at Layer.handle [as handle_request] (/Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/index.js:328:13)
at /Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/index.js:286:9
at Function.process_params (/Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/index.js:346:12)
at next (/Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/index.js:280:10)
[...]
The local dev server should start and build the app.
Actual result
In the browser you see the 'Internal Server Error'.
Stack trace (excerpt) from the terminal:
Uncaught exception: TypeError: (0 , _crypto.randomUUID) is not a function
at /Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/pwa-kit-dev/ssr/server/build-dev-server.js:105:53
at Layer.handle [as handle_request] (/Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/index.js:328:13)
at /Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/index.js:286:9
at Function.process_params (/Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/index.js:346:12)
at next (/Users/tfoerster/Documents/Salesforce/pwa-kit-starter-project/node_modules/express/lib/router/index.js:280:10)
[...]
A local temporary solution/workaround is to replace the code line with res.locals.requestId = _crypto.randomBytes(20).toString('hex'); -> at least the dev server starts then. It might also work to use Node 14.17.0, but I didn't test that yet, and the documentation/package.json should be updated if this is a requirement.
Summary
When you create a new starter app project following the Quick Start instructions with v2.3.0, the startup of the local dev server fails with an error:
Steps To Reproduce
Run
npx pwa-kit-create-app@latest --preset retail-react-app-demo
Start the local web server:
Expected result
The local dev server should start and build the app.
Actual result
In the browser you see the 'Internal Server Error'.
Stack trace (excerpt) from the terminal:
System Information (as applicable)
Browser: Chrome (or any other) Node version: 14.0.0 NPM version: 6.14.4 pwa-kit version: 2.3.0 Desktop OS: iOS
Additional information
The issue here is that function crypto.randomUUID() is not available with Node 14.0.0. It was added with Node 14.17.0/15.6.0 - see https://nodejs.org/api/crypto.html#cryptorandomuuidoptions
A local temporary solution/workaround is to replace the code line with res.locals.requestId = _crypto.randomBytes(20).toString('hex'); -> at least the dev server starts then. It might also work to use Node 14.17.0, but I didn't test that yet, and the documentation/package.json should be updated if this is a requirement.