vue create で作成したプロジェクトでコンパイルエラーが発生した場合


vue createでプロジェクトを作成

vue create my-project

質問をマニュアルで進め、無事プロジェクトの作成に成功したので開発サーバーを起動します。

cd my-project
npm run serve

エラー発生

すると、次のようなエラーが

 ERROR  Failed to compile with 1 errors                                         

error  in ./src/main.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: [BABEL] <project-path>/my-project/src/main.js: Package exports for 
'<project-path>my-project/node_modules/@babel/helper-compilation-targets'
do not define a '.' subpath (While processing: 
"<project-path>/my-project/node_modules/@vue/cli-plugin-babel/preset.js")

解決策

Node.jsのバージョンを13.2.0以上にあげる必要があります。

Node.jsのバージョンを上げる方法

nをインストール

Node.jsのバージョン管理ツールであるnをインストールします。

npm install -g n

最新バージョンを確認

n --stableで安定版、n --latestで最新版を確認できます。
2019/1/20 現在の実行結果です。

n --stable
12.14.1
n --latest
13.6.0

最新版をインストール

n latest

sudoが要求されたら、sudo n latestのようにして実行してください。

インストールされたかバージョンを確認します。

node -v

もう一度プロジェクトを作成。無事解決することができました。

参考サイト

Error: Package exports for /node_modules/@babel/helper-compilation-targets' do not define a '.' subpath
Node.jsとnpmをアップデートする方法 | Rriver