Nuxt / Vue-meta:info.meta.filter不是函数

时间:2019-12-18 13:03:25

标签: webpack vuejs2 nuxt.js nuxt vue-meta

我正在一个在通用模式下运行Nuxt的网站上工作。我们已经与另一个开发人员一起进行了几个月的研究。我们使用Git在不同的分支机构上进行协作,然后在发布新版本的网站时的某些时候进行整合。

自昨天以来,我们遇到了无法正确解释的问题。每当我尝试运行nuxtnuxt generatenpm install <package-name>时,应用程序都会因相同的错误而崩溃:

enter image description here

我们怀疑它可能与package.json中最近的 Babel / Webpack 升级有关,因为我们得到的错误还提到了一些core-js错误。所有这一切的奇怪之处在于,当我们恢复到旧的提交时,应用程序仍然会崩溃,并产生完全相同的错误。只有在我们本地删除该存储库并再次克隆该存储库并使用npm install安装所有依赖项之后,我们才能还原到同一提交并重新启动网站。

我们的package.json中的一些其他信息:

"scripts": {
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "dev": "HOST=0.0.0.0 nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "gsap": "^3.0.1",
    "nuxt": "^2.10.2",
    "swiper": "^5.2.1",
    "vue-svg-loader": "^0.12.0"
  },
  "devDependencies": {
    "@nuxtjs/eslint-config": "^1.1.2",
    "@nuxtjs/eslint-module": "^0.2.1",
    "babel-eslint": "^10.0.3",
    "eslint": "^5.15.1",
    "eslint-config-prettier": "^4.1.0",
    "eslint-plugin-nuxt": "^0.5.0",
    "eslint-plugin-prettier": "^3.1.1",
    "node-sass": "^4.13.0",
    "nodemon": "^1.19.4",
    "prettier": "^1.19.1",
    "sass-loader": "^7.3.1"
  },
  "config": {
    "nuxt": {
      "host": "188.166.41.47",
      "port": "3000"
    }
  }

在删除package-lock.jsonnode_modules文件夹和.nuxt文件夹之后,我们尝试再次运行npm install。这导致安装成功,尽管出现一个错误:

npm WARN不赞成使用core-js@2.6.11:由于问题数量大,不再维护core-js @ <3,也不建议使用它。请将您的依赖项升级到core-js @ 3的实际版本。

但这不是我们已经在package.json中明确注册的内容。

3 个答案:

答案 0 :(得分:1)

修复-将meta更改为对象数组。请参阅下面的说明。

我自己遇到了这个问题,并且找到了简单的解决方法。 filter()是数组构造函数的内置方法。这意味着我们调用该方法的对象不是数组。

我的代码如下:

<template>
    <div>
        <div>                    
            <h1>Events</h1>          
        </div>
    </div>
</template>

<script>
export default {
    head(){
        return {
            title: 'Sergiu Mare - Home page',
            meta: {
                hid: 'description',
                name: 'description',
                content: 'All the information that are about the freelancer Sergiu Mare.'
            }
        }
    }
}
</script>

然后我将其更改为

<template>
    <div>
        <div>                    
            <h1>Events</h1>          
        </div>
    </div>
</template>

<script>
export default {
    head(){
        return {
            title: 'Sergiu MAre - Home page',
            meta: [
                {hid: 'description'},
                {name: 'description'},
                {content: 'All the information that are about the freelancer Sergiu Mare.'}
            ]
        }
    }
}
</script>

现在,如果我检查页面,则元信息就在那里。

enter image description here

答案 1 :(得分:0)

package-lock.json文件以来,您已经克服了第一个问题。

第二个应该通过更新依赖项来解决,如果它没有破坏任何东西,可能是nuxt在使用core-js,因此您可以尝试将该依赖项升级到最新版本(2.11.0),否则,如果您希望警告消失,那就只是一步一步地升级(这只是一个警告,因此您可以暂时将其保留为我们)

答案 2 :(得分:0)

可能有点晚了,但是如果有core-js错误

yarn add --dev core-js@2 @babel/runtime-corejs2

npm install core-js@2 @babel/runtime-corejs2

可以帮助