问题:

在使用create-vite-app vue3-camp创建项目时失败,报错如下:

/usr/local/lib/node_modules/create-vite-app/node_modules/fs-extra/lib/mkdirs/make-dir.js:85
      } catch {
              ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/create-vite-app/node_modules/fs-extra/lib/mkdirs/index.js:3:44)

原因:

node版本过低导致;

解决方法:

更新node版本,我从v8.11.2 >> v12.19.0;

步骤

  1. node -v(查看当前node版本)
  2. sudo npm cache clean -f (回车后需要输入电脑登录密码)
  3. sudo npm install -g n (n是node版本管理工具)
  4. sudo n stable (更新到最新的稳定版node)
  5. node -v (查看更新后node版本)

Tips

在执行步骤4时,碰到了下面这个问题,可能是因为网络vpn导致,把网络切换到手机热点,重新执行就成功了

QC:Downloads qc$ sudo n stable
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to nodejs.org:443
Error: failed to download version index (https://nodejs.org/dist/index.tab)
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐