问题描述
我正在尝试在github上创建一个远程vue cli预设,但是由于某种原因,我一直收到语法错误。
我的预设存储库:https://github.com/christoph-schaeffer/vue-preset
我输入的命令:vue create --preset christoph-schaeffer / vue-preset testProject
我得到的错误:
? 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)
起初它工作正常,然后我在预置文件中添加了一些内容以及生成器模板。
在收到错误后,我尝试将整个存储库恢复到其仍在工作的状态。但是我仍然收到该错误...
我想这不是真的与预设有关,而是与我的全局babel包有关的问题?
我正在使用vue-cli版本4,并且正在Mac上运行
高度赞赏我如何进行此操作的任何指示
解决方法
我找到了问题。
首先:vue cli似乎以某种方式缓存了远程预设。这就是为什么即使还原更改后它也无法起作用的原因。
实际的问题是,main.js不应像其他模板文件一样进行更改,需要特别注意。由于某些奇怪的原因,一旦模板中包含main.js,它就会立即产生那些随机错误。
如果有人对如何通过预设签出来修改main.js感到好奇: https://cli.vuejs.org/dev-guide/plugin-dev.html#changing-main-file