【问题标题】:Angular2- Meteor, npm package not recognizedAngular2- Meteor,npm 包无法识别
【发布时间】:2017-07-31 13:51:02
【问题描述】:

我是一个新手,试图在我的 angular2-meteor 应用程序中使用 kiteconnect npm pacakge,但是当我尝试在我的 app.module.ts 中导入这个包时,它说找不到模块“KiteConnect”。 下面是我在 import 语句下面使用的语句

import {KiteConnect}   from 'KiteConnect';

我确信这是非常愚蠢的事情,但有人可以指出我在这里做错了什么。

以下是我的 package.json 的摘录

{
  "name": "socially",
  "private": true,
  "scripts": {
    "start": "meteor run",
    "test": "meteor test --driver-package practicalmeteor:mocha",
    "test:ci": "meteor test --once --driver-package dispatch:mocha-phantomjs"
  },
  "dependencies": {
    "@angular/common": "2.1.2",
    "@angular/compiler": "2.1.2",
    "@angular/core": "2.1.2",
    "@angular/forms": "2.1.2",
    "@angular/platform-browser": "2.1.2",
    "@angular/platform-browser-dynamic": "2.1.2",
    "@angular/router": "3.1.2",
    "angular2-meteor": "0.7.0",
    "angular2-meteor-accounts-ui": "^1.0.0",
    "angular2-meteor-polyfills": "0.1.1",
    "angular2-meteor-tests-polyfills": "0.0.2",
    "kiteconnect": "^1.1.1",
    "meteor-node-stubs": "0.2.3",
    "meteor-rxjs": "0.4.3",
    "meteor-typings": "1.3.1",
    "reflect-metadata": "0.1.8",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "0.6.26"
  },
  "devDependencies": {
    "@types/chai": "^3.4.33",
    "@types/mocha": "^2.2.32",
    "chai": "3.5.0",
    "chai-spies": "0.7.1"
  }
}

我也尝试过使用包“chalk”,但在导入时又出现了同样的问题。现在我怀疑是因为编辑器(我正在使用 webstorm)还是由于 tsconfig.josn 如下:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "es6",
      "dom"
    ],
    "module": "commonjs",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules"
  ],
  "files": [
    "typings.d.ts"
  ],
  "compileOnSave": true,
  "angularCompilerOptions": {
    "genDir": "aot",
    "skipMetadataEmit": true
  }
} 

【问题讨论】:

  • 可以添加来自您的packages.json 的摘录吗?
  • @LibinVarghese,
  • @LibinVarghese,我已经更新了我的问题中的 package.json

标签: angular meteor npm webstorm packages


【解决方案1】:

在调用 meteor npm install kiteconnect 后尝试使用 var KiteConnect = require('kiteconnect').KiteConnect;

【讨论】:

  • 是的,但是我首先需要在@NgModuleand 中注入依赖项,以便我可以在我的angular2组件中使用它,为此我首先需要导入kiteConnect,但这在导入中无法识别声明
  • 很奇怪。我只是将import { KiteConnect } from 'KiteConnect'; console.log(new KiteConnect()); 放在我的 router.js 文件的顶部,它就起作用了。你打电话给meteor npm install了吗?你还在做什么?
  • 确实很奇怪,我使用了“Meteor npm install --save kiteconnect”,我可以在节点模块中看到 kiteconnect,但我无法使用 import 语句访问它。我在 app.module.ts 使用“ import { KiteConnect } from 'KiteConnect'; ”,这是我在 angular2 应用程序中的入口文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-20
  • 2015-06-28
  • 2023-04-08
相关资源
最近更新 更多