【问题标题】:Collection is not defined after a bare meteor install on windows 10在 Windows 10 上安装裸流星后未定义集合
【发布时间】:2020-09-01 21:26:22
【问题描述】:

这个新安装的流星(1.10.2)由 Chocolatey 在 Windows 10 上,然后是 meteor create --bare appName 然后复制/粘贴一些我已经停放了一段时间的 2 岁代码。追寻此运行时错误的原因无济于事。

ReferenceError: DataTeckCol is not defined
at server/dataTeck.js:13:1
at module (server/dataTeck.js:20:8)

../server/dataTeck.js

"use strict";
let cheerio = require('cheerio');
import {Matcher} from "./matcher";
import {Dispatcher} from "./dispatcher";
import '../imports/api/dataTeck.js';

DataTeckCol.remove({plateNum: {$in: plates}});  //<<<<<<<< Error line

../imports/api/dataTeck.js

import { Mongo } from 'meteor/mongo';
export const DataTeckCol = new Mongo.Collection('dataTeckCol');

【问题讨论】:

    标签: meteor collections


    【解决方案1】:

    你需要显式地导入导出的常量,所以不是

    import '../imports/api/dataTeck.js';
    

    您需要通过以下方式导入它

    import { DataTeckCol } from '../imports/api/dataTeck.js';
    

    【讨论】:

    • 这是否意味着每个集合都需要在 api 文件夹下的自己的文件中声明,并且每次需要引用时,import 语句都需要位于文件的顶部,是有没有一种同样模块化的方式,需要更少的打字和维护?
    • 您可以在全局范围内定义它,然后只需要导入一次,但全局范围是一种反模式。自动完成变量时,您的 ide 应自动解析导入。使用开箱即用的 webstorm,使用 vs code 你需要安装一个插件然后它也可以工作。
    猜你喜欢
    • 2015-10-28
    • 2015-02-23
    • 2016-07-29
    • 1970-01-01
    • 2013-06-30
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    相关资源
    最近更新 更多