0

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?

jack07Code
  • 31
  • 1
  • 5

1 Answers1

1

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.

tony19
  • 125,647
  • 18
  • 229
  • 307