即使在node_modules中,也找不到ag-grid-vue模块

时间:2019-12-09 17:07:26

标签: javascript node.js vue.js ag-grid ag-grid-vue

我正在逐步遵循Vue.js AgGrid入门指南:https://www.ag-grid.com/vuejs-grid/

添加<script>部分并保存后,会出现以下错误:

ERROR  Failed to compile with 1 errors                              12:01:18 PM

This dependency was not found:

* ag-grid-vue 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/App.vue?vue&type=script&lang=js&

To install it, you can run: npm install --save ag-grid-vue
Type checking in progress...
No type errors found
Version: typescript 3.5.3
Time: 1125ms

问题是我已经使用指南中的命令安装了它:

npm install --save ag-grid-community ag-grid-vue vue-property-decorator

我已经检查了node_modules,似乎一切都在那里。 到目前为止,这是我在App.vue中拥有的代码:

<template>
    <ag-grid-vue style="width: 500px; height: 500px;"
                 class="ag-theme-balham"
                 :columnDefs="columnDefs"
                 :rowData="rowData">
    </ag-grid-vue>
</template>

<style lang="scss">
  @import "../node_modules/ag-grid-community/dist/styles/ag-grid.css";
  @import "../node_modules/ag-grid-community/dist/styles/ag-theme-balham.css";
</style>

<script>
    import {AgGridVue} from "ag-grid-vue";

    export default {
        name: 'App',
        data() {
            return {
                columnDefs: null,
                rowData: null
            }
        },
        components: {
            AgGridVue
        },
        beforeMount() {
            this.columnDefs = [
                {headerName: 'Make', field: 'make'},
                {headerName: 'Model', field: 'model'},
                {headerName: 'Price', field: 'price'}
            ];

            this.rowData = [
                {make: 'Toyota', model: 'Celica', price: 35000},
                {make: 'Ford', model: 'Mondeo', price: 32000},
                {make: 'Porsche', model: 'Boxter', price: 72000}
            ];
        }
    }
</script>

知道发生了什么吗?如果这很重要,请在MacOS Catalina上,并使用最新的LTS版本的Node(今天早上才下载)。我还尝试了卸载并重新安装节点(“完全”方式也删除了所有隐藏的节点文件夹和东西,然后从站点重新安装)。

1 个答案:

答案 0 :(得分:1)

似乎ag-grid入门文档已过时。现在要安装的正确软件包是基于模块的。

例如package.json中的依赖项下:

"@ag-grid-community/all-modules": "~22.1.0",
"@ag-grid-community/client-side-row-model": "~22.1.0",
"@ag-grid-community/core": "~22.1.0",
"@ag-grid-community/csv-export": "~22.1.0",
"@ag-grid-community/infinite-row-model": "~22.1.0",
"@ag-grid-community/vue": "~22.1.0",
"@ag-grid-enterprise/all-modules": "~22.1.0",

然后在组件的<script>中:

import {AgGridVue} from "@ag-grid-community/vue";
import {AllCommunityModules} from '@ag-grid-community/all-modules';

export default下的“数据”中:

data() {
    return {
        columnDefs: null,
        rowData: null,
        modules: AllCommunityModules
    }
},

最后进入<template>

<template>
    <ag-grid-vue style="width: 500px; height: 500px;"
                  class="ag-theme-balham"
                 :columnDefs="columnDefs"
                 :rowData="rowData"
                 :modules="modules">
    </ag-grid-vue>
</template>

https://www.ag-grid.com/javascript-grid-modules/#installing-ag-grid-modules为此提供了很多帮助。他们确实需要更新其入门页面!