Vue ui 提示 Cannot read properties of undefined (reading ‘indexOf’)
Vue ui 提示 Cannot read properties of undefined (reading ‘indexOf’)

Vue ui 提示 Cannot read properties of undefined (reading ‘indexOf’)

安装Vue ui后,创建新项目时,提示

Cannot read properties of undefined (reading 'indexOf')

终端提示下述报错:

(node:5527) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
🚀  Starting GUI...
🌠  Ready on http://localhost:8000
(node:5634) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! code EEXIST
npm ERR! syscall mkdir
npm ERR! path /Users/fangjunyu/.npm/_cacache/content-v2/sha512/d6/1b
npm ERR! errno EEXIST
npm ERR! Invalid response body while trying to fetch https://registry.npmmirror.com/@babel%2fcore: EACCES: permission denied, mkdir '/Users/fangjunyu/.npm/_cacache/content-v2/sha512/d6/1b'
npm ERR! File exists: /Users/fangjunyu/.npm/_cacache/content-v2/sha512/d6/1b
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

npm ERR! A complete log of this run can be found in: /Users/fangjunyu/.npm/_logs/2024-04-23T11_09_53_392Z-debug-0.log
 ERROR  Error: command failed: npm install --loglevel error --legacy-peer-deps
Error: command failed: npm install --loglevel error --legacy-peer-deps
    at ChildProcess.<anonymous> (/usr/local/lib/node_modules/@vue/cli/lib/util/executeCommand.js:138:16)
    at ChildProcess.emit (node:events:519:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5)
Error: Command failed: vue create face_red --skipGetStarted --git initializing the git repository for the first time --inlinePreset {"vueVersion":"3","useConfigFiles":false,"plugins":{"@vue/cli-plugin-babel":{},"@vue/cli-plugin-eslint":{"config":"base","lintOn":["save"]}}}
✨  Creating project in /Users/fangjunyu/文稿/Vue学习/face_red.
🗃  Initializing git repository...
⚙️  Installing CLI plugins. This might take a while...

    at makeError (/usr/local/lib/node_modules/@vue/cli/node_modules/execa/index.js:174:9)
    at /usr/local/lib/node_modules/@vue/cli/node_modules/execa/index.js:278:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /usr/local/lib/node_modules/@vue/cli/node_modules/@vue/cli-ui/apollo-server/connectors/projects.js:354:5
    at async Object.wrap (/usr/local/lib/node_modules/@vue/cli/node_modules/@vue/cli-ui/apollo-server/connectors/progress.js:39:14) {
  code: 1,
  stdout: '✨  Creating project in /Users/fangjunyu/文稿/Vue学习/face_red.\n' +
    '🗃  Initializing git repository...\n' +
    '⚙️  Installing CLI plugins. This might take a while...\n' +
    '\n',
  stderr: null,
  failed: true,
  signal: null,
  cmd: 'vue create face_red --skipGetStarted --git initializing the git repository for the first time --inlinePreset {"vueVersion":"3","useConfigFiles":false,"plugins":{"@vue/cli-plugin-babel":{},"@vue/cli-plugin-eslint":{"config":"base","lintOn":["save"]}}}',
  timedOut: false,
  killed: false
}

问题原因

Vue ui 会自动将包管理器设置为yarn,因为操作电脑没有安装yarn导致报错。

解决方案

执行下列代码安装yarn:

sudo npm install -g yarn

安装完成后,问题解决。

参考资料

Vue UI throws error message ‘cannot read properties of undefined (reading ‘indexOf’)’ https://github.com/vuejs/vue-cli/issues/6880

如果您认为这篇文章给您带来了帮助,您可以在此通过支付宝或者微信打赏网站开放者。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注