vue.jsvuejs2vue-clivue-cli-4

Vue Cli remote preset crashes on Invoking Generators


i'm trying to create a remote vue cli preset on github, but for some reason i keep getting a syntax error.

My preset repo: https://github.com/christoph-schaeffer/vue-preset

The command i have entered: vue create --preset christoph-schaeffer/vue-preset testProject

The Error i get:

🚀  Invoking generators...
 ERROR  SyntaxError: Identifier 'router' has already been declared (15:7)
SyntaxError: Identifier 'router' has already been declared (15:7)
    at Object._raise (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:762:17)
    at Object.raiseWithData (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:755:17)
    at Object.raise (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:749:17)
    at ScopeHandler.checkRedeclarationInScope (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:4826:12)
    at ScopeHandler.declareName (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:4792:12)
    at Object.checkLVal (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:9367:22)
    at Object.checkLVal (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:865:15)
    at Object.parseImportSpecifierLocal (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:12706:10)
    at Object.maybeParseDefaultImportSpecifier (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:12751:12)
    at Object.parseImport (/usr/local/lib/node_modules/@vue/cli/node_modules/@babel/parser/lib/index.js:12677:31)

At first it worked fine, then i've added several things in the preset.json along with a generator template.

After getting the error i've tried reverting the whole repo to the state it had when it was still working. However i still get that error...

I guess it's not really about the preset but instead an issue with my global babel package or something?

I'm using vue-cli version 4 and im working on a mac

Any directions on how i could get this running would be highly appreciated


Solution

  • I've found the issue.

    First: the vue cli somehow seems to cache remote presets. That's the reason why it didn't work even after reverting changes.

    The actual issue was, that the main.js shouldn't be changed like the other template files and needs special attention. For some weird reason it gives those random errors as soon as you have a main.js in your template.

    If anyone is curious on how to modify your main.js in a preset check out : https://cli.vuejs.org/dev-guide/plugin-dev.html#changing-main-file