LoginSignup
14
12

More than 5 years have passed since last update.

Failed to mount component: template or render function not defined. (found in root instance) の対応

Posted at

Webpack で Vue.js 2 を含めてビルドした場合、実行時にタイトルのエラーが発生した。

公式ドキュメントでは、下記にて解説されている。
https://vuejs.org/v2/guide/installation.html#Standalone-vs-Runtime-only-Build

ポイントは、下記。

  • Vue.js では、スタンドアロン版とランタイムのみ版がある。
  • 前者はテンプレートコンパイラを含み、後者は無い。
  • デフォルトでは、NPM パッケージでは、ランタイムのみ版をエクスポートする。
  • このテンプレートコンパイラが無いためにエラーが発生する。

Webpack によるビルドでスタンドアロン版を含めるなら、下記を webpack.config.js で設定すれば良い。

webpack.config.js
module.exports = {
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.common.js'
        }
    }
};
14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12