【问题标题】:this.array.ForEach dependencies not found with VueCLI使用 Vue CLI 找不到 this.array.ForEach 依赖项
【发布时间】:2020-05-31 02:06:14
【问题描述】:

这是我的代码。我正在使用 VueCLI。

产生问题的行是this.slides.forEach(..

我遇到的错误是dependencies not found(下面是完整错误)。

当我安装缺少npm install --save core-js/modules/es.array.for-each core-js/modules/web.dom-collections.for-each 的依赖项时,出现es.array.for-each does not contain a package.json file 错误

然后我在错误中描述的位置创建了 package.json 文件。我运行npm install 但我有同样的package.json not found 错误。

这里有什么问题的线索吗?

<template>
    <div>
        <slot>

        </slot>
    </div>
</template>

<script>
export default {
    data (){
        return{
            index: 0,
            slides: []
        }
    },
    mounted(){
        this.slides = this.$children

        this.slides.forEach((slide, i) => {
            slide.index = i
        })
    }
}
</script>

<style lang="css">

</style>

 ERROR  Failed to compile with 2 errors                                                                                                                                                                 10:39:10 AM
These dependencies were not found:

* core-js/modules/es.array.for-each in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Carousel/Carousel.vue?vue&type=script&lang=js&
* core-js/modules/web.dom-collections.for-each in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Carousel/Carousel.vue?vue&type=script&lang=js&

To install them, you can run: npm install --save core-js/modules/es.array.for-each core-js/modules/web.dom-collections.for-each

npm ERR! code ENOLOCAL
npm ERR! Could not install from "core-js\modules\es.array.for-each" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     User\...\AppData\Roaming\npm-cache\_logs\2020-02-15T15_49_17_958Z-debug.log

【问题讨论】:

    标签: javascript npm npm-install vue-cli


    【解决方案1】:

    找到答案了。

    npm install --save-dev @vue/cli @vue/cli-service-global core-js@3

    成功了!我认为 core-js@2 存在一些问题

    【讨论】:

    • 这很奇怪,因为这不应该是必要的。它也开始发生在我身上,我不知道为什么。这是我用forEach 迭代的NodeList(用querySelectorAll 选择)。
    猜你喜欢
    • 2020-03-26
    • 1970-01-01
    • 2019-02-14
    • 2022-01-01
    • 2019-02-05
    • 2021-08-03
    • 2021-11-09
    • 2019-01-25
    • 1970-01-01
    相关资源
    最近更新 更多