【问题标题】:Typescript Cannot find module 'meteor/easy:search'打字稿找不到模块“流星/简单:搜索”
【发布时间】:2018-03-26 18:08:14
【问题描述】:

我的目标是在 Urigo 的 meteor-angular2.0 示例中使用 ElasticSearch(请参见下面的链接)。

为此,我尝试在基于 https://github.com/Urigo/meteor-angular2.0-socially 的现有项目中使用 easysearch:elasticsearch 包。

在我使用meteor add easysearch:elasticsearch 之后,如果我尝试实现它(服务器端/客户端/两者——没关系),我总是会收到Cannot find module error。 这是我在both/collections/cases.collections.ts 文件中的实现代码:

import { MongoObservable } from "meteor-rxjs";
import { Meteor } from 'meteor/meteor';
import { Index } from 'meteor/easy:search' // gives error
import { ElasticSearchEngine } from 'meteor/easysearch:elasticsearch' //gives error

import { Case } from "../models/case.model";

export const Cases = new MongoObservable.Collection<Case>("cases");

// const CasesIndex = new Index({
//   collection: Cases,
//   fields: ['name', 'description'],
//   engine: new ElasticSearchEngine({
//     body: () => { } // modify the body that's sent when searching
//   })

function loggedIn() {
  return !!Meteor.user();
}

Cases.allow({
  insert: loggedIn,
  update: loggedIn,
  remove: loggedIn
});

我的.meteor/packages 文件有以下内容:

# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

meteor-base@1.0.4             # Packages every Meteor app needs to have
mobile-experience@1.0.4       # Packages for a great mobile UX
mongo@1.1.14                   # The database Meteor supports right now
reactive-var@1.0.11            # Reactive variable for tracker
tracker@1.1.1                 # Meteor's client-side reactive programming library

standard-minifier-css@1.3.2   # CSS minifier run for production mode
standard-minifier-js@1.2.1    # JS minifier run for production mode
es5-shim@4.6.15                # ECMAScript 5 compatibility for older browsers.

angular2-compilers
practicalmeteor:mocha
xolvio:cleaner
hwillson:stub-collections
dispatch:mocha-phantomjs
shell-server@0.2.1
accounts-password
anti:fake
tmeasday:publish-counts
check
email
jalik:ufs
jalik:ufs-gridfs
mickaelfm:vermongo
easysearch:elasticsearch
easysearch:core
easy:search

另外(如果有帮助的话)我的package.json

{
  "name": "a angular2 elasticsearch site",
  "private": true,
  "scripts": {
    "start": "meteor run",
    "start:prod": "meteor run --production",
    "build": "meteor build ./build/",
    "clear": "meteor reset",
    "meteor:update": "meteor update --all-packages",
    "test": "meteor test --driver-package practicalmeteor:mocha",
    "test:ci": "meteor test --once --driver-package dispatch:mocha-phantomjs"
  },
  "devDependencies": {
    "@types/chai": "3.5.2",
    "@types/meteor": "^1.4.1",
    "@types/mocha": "2.2.41",
    "chai": "3.5.0",
    "chai-spies": "0.7.1",
    "meteor-node-stubs": "0.2.4"
  },
  "dependencies": {
    "@angular/animations": "^4.4.3",
    "@angular/common": "^4.4.3",
    "@angular/compiler": "^4.4.3",
    "@angular/core": "^4.4.3",
    "@angular/forms": "^4.4.3",
    "@angular/http": "^4.4.3",
    "@angular/material": "2.0.0-beta.8",
    "@angular/platform-browser": "^4.4.3",
    "@angular/platform-browser-dynamic": "^4.4.3",
    "@angular/router": "^4.4.3",
    "@types/node": "^7.0.22",
    "@types/underscore": "^1.8.1",
    "angular2-file-drop": "^0.2.0",
    "angular2-google-maps": "0.17.0",
    "angular2-meteor": "0.7.1",
    "angular2-meteor-accounts-ui": "1.0.0",
    "angular2-meteor-polyfills": "0.2.0",
    "angular2-meteor-tests-polyfills": "0.0.2",
    "babel-runtime": "6.23.0",
    "bcrypt": "=1.0.2",
    "gm": "^1.23.0",
    "hammerjs": "^2.0.8",
    "meteor-node-stubs": "0.2.11",
    "meteor-rxjs": "0.4.7",
    "meteor-typings": "1.3.1",
    "ng2-drag-drop": "^2.0.1",
    "ng2-pagination": "^2.0.1",
    "reflect-metadata": "0.1.10",
    "ng2-cytoscape": "0.4.0",
    "rxjs": "5.4.0",
    "zone.js": "0.8.11"
  }
}

仍然是同样的错误 - 我添加了带有 meteor add easy:search 的包,并通过 npm run start 重建了整个应用程序。

此外,我将导入转移到服务器端 - 只是为了确保没有问题,但我仍然在 Atom 编辑器和 chrome 控制台中收到错误。

会不会是因为我没有使用 Blaze 组件而遇到一些问题?

【问题讨论】:

    标签: angular typescript meteor module meteor-easy-search


    【解决方案1】:

    您忘记安装 easy:search 包本身。

    cd /path/to/project
    meteor add easy:search
    

    【讨论】:

    • 仍然是同样的错误 - 我已经添加了带有流星的软件包 add easy:search 并通过 npm run start 重建整个应用程序。
    • 如果我另外添加 'npm-debug-log' 会有帮助吗?
    • @SaschaN。它可以。
    【解决方案2】:

    我想通了 - 任何东西都安装得很好,但是编译器、编辑器(带有 Typescript 包的 Atom)和控制台因为缺少输入而给我一个错误。

    刚刚将以下错误的最小类型定义添加到typings.d.ts 以成功连接到正在运行的elasticsearch 服务器。

    declare module 'meteor/easysearch:core' {
      import { Mongo } from "meteor/mongo";
    
      interface config {
        collection: any,
        fields: string[],
        engine: any
      }
    
      class Index {
        constructor(config: config);
        search(searchDefinition: string, options?: object): Mongo.Cursor<any>;
      }
    }
    
    
    declare module 'meteor/easysearch:elasticsearch' {
      interface params {
        body: any
      }
    
      class ElasticSearchEngine {
        constructor(obj: params);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-18
      • 2021-01-07
      • 2013-12-30
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      相关资源
      最近更新 更多