'permission issue with npm init vue@latest in Ubuntu 20.04

I want to install vue 3 in a way that I choose the presets like this in my wsl2 ubuntu.

What I did was:

  1. sudo mkdir /var/www/myproj.com

  2. cd /var/www/myproj.com

  3. npm init vue@latest - but this one has EACCESS: Permission denied error

  4. So I did sudo npm init vue@latest, but this one generates the error below

    npx: installed 1 in 3.153s
    /root/.npm/_npx/3489/lib/node_modules/create-vue/outfile.cjs:5681
      const isFeatureFlagsUsed = typeof (argv.default ?? argv.ts ?? argv.jsx ?? argv.router ?? 
    argv.pinia ?? argv.tests ?? argv.vitest ?? argv.cypress ?? argv.eslint) === "boolean";
    
    SyntaxError: Unexpected token ?
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
    

From here, I honestly don't know what to do.

npm and node versions:

npm = 6.14.16
node = v14.19.1

New to linux, so please bear with me :)



Solution 1:[1]

I got exactly the same issue (at point 4) and updating to node 16 did the trick for me (I was still using the v12 btw).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1