I'm trying to run npm init vite on Ubuntu 22.04 LTS and node v12.22.9, but it gaves me this error
file:///home/giacomo/.npm/_npx/2c4a09cdd3a6d615/node_modules/create-vite/index.js:296
return targetDir?.trim().replace(/\/+$/g, '')
^
SyntaxError: Unexpected token '.'
at Loader.moduleStrategy (internal/modules/esm/translators.js:133:18)
at async link (internal/modules/esm/module_job.js:42:21)
npm ERR! code 1
npm ERR! path /home/giacomo/Scrivania/html/3DWebApp
npm ERR! command failed
npm ERR! command sh -c create-vite
npm ERR! A complete log of this run can be found in:
npm ERR! /home/giacomo/.npm/_logs/2022-07-25T05_58_55_401Z-debug-0.log
I've tried other methods like npm init @vitejs/app or npm create @vitejs/app but they're deprecated.
There's a way i can manually fix it or there is another method to try?
The error points to the optional chaining syntax (?.), which is not supported in Node 12.22.9. That feature was introduced in Node 14.
Also Vite 3 docs indicate the minimum Node version required:
Compatibility Note
Vite requires Node.js version >=14.18.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
You should upgrade your version of Node (e.g., using n). The current latest version is Node 18.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With