Node.js 12 applications failing by Optional chaining
This change can be affecting Node.js <=12 applications which have npm modules dependencies that are implementing optional chaining in their code.
(Screenshot taken from https://node.green)
Some scenarios are described below:
npx serve -s
npx serve -s without having installed the module before, it will fetch the latest version (currently v14). This new version requires at least Node.js 14 version to run, otherwise it will fail with the following error:
npx serve -s npx: installed 91 in 29.345s file:///root/.npm/_npx/108/lib/node_modules/serve/build/main.js:130 url.port = url.port ?? "3000"; ^ SyntaxError: Unexpected token '?' at Loader.moduleStrategy (internal/modules/esm/translators.js:140:18) at async link (internal/modules/esm/module_job.js:42:21)
You can mitigate this error with the following options:
npx serve@13 -s, which will pull the latest 13 version (13.0.4) Or
- Install firstname.lastname@example.org version with
npm install email@example.com --saveand then you can use
npx serve -sand it will pull the version from node_modules folder Or
- Upgrade your application to use Node.js 14 version.
You can find other issues reported by the community: