vue init webpack创建项目报错TypeError

/Users/xxx/.nvm/versions/node/v12.22.12/lib/node_modules/@vue/cli-init/node_modules/metalsmith/lib/helpers.js:2
const { readFile, writeFile, stat, mkdir, chmod, ...fsPromises } = fs.promises
        ^

TypeError: Cannot destructure property `readFile` of 'undefined' or 'null'.
    at Object. (/Users/xxx/.nvm/versions/node/v12.22.12/lib/node_modules/@vue/cli-init/node_modules/metalsmith/lib/helpers.js:2:71)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object. (/Users/xxx/.nvm/versions/node/v12.22.12/lib/node_modules/@vue/cli-init/node_modules/metalsmith/lib/watcher.js:7:16)
    at Module._compile (internal/modules/cjs/loader.js:678:30)

问题根源:node版本过低导致

使用nvm查看已经安装的node进行切换版本即可

 ls
       v10.16.3
->    v12.22.12
       v16.19.0
default -> 12.22.12 (-> v12.22.12)
node -> stable (-> v16.19.0) (default)
stable -> 16.19 (-> v16.19.0) (default)
iojs -> N/A (default)
lts/* -> lts/iron (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.19.0 (-> N/A)
lts/iron -> v20.10.0 (-> N/A)

切换到16.19.0 

nvm use default 16.19.0

Now using node v16.19.0 (npm v8.19.3)

nvm ls

       v10.16.3

      v12.22.12

->     v16.19.0

再次执行 vue init webpack vue-demo

vue init webpack创建项目报错TypeError_第1张图片 vue init webpack创建项目报错TypeError_第2张图片

你可能感兴趣的:(前端,vue.js,webpack,前端)