5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Nuxt.js】create-nuxt-appする際、element-uiを追加すると出るreference errorの対処法

Last updated at Posted at 2019-05-10

Nuxt.jsの新しいプロジェクトを立ち上げる際、UIフレームワークのelement-uiを追加し、create-nuxt-appのコマンドを使って行ったのですが、サーバの立ち上げでエラーが発生してしまったのでその対処法を書いておきます。

create-nuxt-appでプロジェクトを立ち上げる

普段通りcreate-nuxt-appでプロジェクトを立ち上げ、いくつかの質問に答えていきます。

$ create-nuxt-app <your-project-name>

しばらくすると、インストールが完了し、サーバの起動が促されます。

To get started: 

$ cd your-nuxt-app 
$ yarn dev

指示されるようにコマンドを叩くと、いつものようにNuxtのトップページが表示されるはずです。

しかし、サーバが正常に起動しないエラーが発生

ところが、今回同様に実行したところ、サーバが正常に起動しないエラーが発生しました。HTMLElement is not definedというreference errorが発生した模様です。

Screen Shot 2019-05-10 at 14.14.36.jpg

原因はelement-ui.common.js内の記述にあった

調べてみると、原因は/node-modules/element-ui/lib/element-ui.common.jsの記述にありました。どうやらこのpropsで渡されている、scrollContainerに問題があるとのこと。

element-ui.common.js
props: {
    src: String,
    fit: String,
    lazy: Boolean,
    scrollContainer: [String, HTMLElement], //この記述が問題
    alt: String
  },

実はこれ、以下のissueでelement ui側ですでに解決しているようです。
https://github.com/ElemeFE/element/pull/15277

ということで、プルリクにあるように、以下のようにelement-ui.common.jsの記述に修正を加えました。

element-ui.common.js
-     scrollContainer: [String, HTMLElement],
+     scrollContainer: {},

すると、無事サーバば正常に起動し、いつものNuxt.jsの画面が表示されました。

Screen Shot 2019-05-10 at 14.20.33.jpg

めでたしめでたし。

参考

https://cmty.app/nuxt/nuxt.js/issues/c9129
https://github.com/ElemeFE/element/pull/15277/commits/8f87eeeabcb3bf8599d50b9c5a3b112197894b4b

5
0
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
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?