vue.jsnpmvuejs3yarnpkg

Vue3 CLI keeps asking about slow internet connection


During an E2E test process I automatically install Vue3 via Vue CLI, the exact command is:

npx --yes @vue/cli create vue3 --packageManager npm -n -i '{"useConfigFiles":true,"plugins":{"@vue/cli-plugin-babel":{},"@vue/cli-plugin-typescript":{"classComponent":false,"useTsWithBabel":true},"@vue/cli-plugin-pwa":{},"@vue/cli-plugin-router":{"historyMode":true},"@vue/cli-plugin-vuex":{},"@vue/cli-plugin-eslint":{"config":"prettier","lintOn":["save"]}},"vueVersion":"3"}'

The problem is, that during the process, this question keeps coming:

?  Your connection to the default yarn registry seems to be slow.
   Use https://registry.npmmirror.com for faster installation? (Y/n)

Since it is waiting for an input, the build fails. How can I deactivate this prompt?


Solution

  • I found the solution by looking at the Vue CLI source code. If you run the create command with the registry parameter, or you can set the environment variable VUE_CLI_TEST to avoid that prompt. Since I don't know what other implications setting the variable has, I run with the registry command. Here's the code from src, shouldUseTaobao is the function that is responsible for the prompt:

        const args = minimist(process.argv, {
          alias: {
            r: 'registry'
          }
        })
    
        let registry
        if (args.registry) {
          registry = args.registry
        } else if (!process.env.VUE_CLI_TEST && await shouldUseTaobao(this.bin)) {
          registry = registries.taobao
        } else {
          try {
            if (scope) {
              registry = (await execa(this.bin, ['config', 'get', scope + ':registry'])).stdout
            }
            if (!registry || registry === 'undefined') {
              registry = (await execa(this.bin, ['config', 'get', 'registry'])).stdout
            }
          } catch (e) {
            // Yarn 2 uses `npmRegistryServer` instead of `registry`
            registry = (await execa(this.bin, ['config', 'get', 'npmRegistryServer'])).stdout
          }
        }