VueCliリモートプリセットがジェネレーターの呼び出しでクラッシュする

Aug 19 2020

githubでリモートvuecliプリセットを作成しようとしていますが、何らかの理由で構文エラーが発生し続けます。

私のプリセットリポジトリ: 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)

最初は問題なく動作し、次にジェネレーターテンプレートとともにpreset.jsonにいくつかのものを追加しました。

エラーが発生した後、リポジトリ全体を、まだ機能しているときの状態に戻してみました。しかし、私はまだそのエラーが発生します...

私はそれが実際にはプリセットについてではなく、代わりに私のグローバルなbabelパッケージか何かの問題だと思いますか?

私はvue-cliバージョン4を使用していて、Macで作業しています

私がこれを実行する方法についての指示は非常に高く評価されます

回答

ChristophDietrich Aug 19 2020 at 16:38

問題を見つけました。

まず、vuecliはどういうわけかリモートプリセットをキャッシュしているようです。これが、変更を元に戻しても機能しなかった理由です。

実際の問題は、main.jsを他のテンプレートファイルのように変更してはならず、特別な注意が必要なことでした。いくつかの奇妙な理由で、テンプレートにmain.jsがあるとすぐに、それらのランダムエラーが発生します。

プリセットでmain.jsを変更する方法に興味がある人は、次のチェックアウトをご覧ください。 https://cli.vuejs.org/dev-guide/plugin-dev.html#changing-main-file