打字稿:找不到自定义库的模块

内特建筑师

问题

当我从ng2-orm中导入Config时,为什么不导入(或被vscode识别)我的ng2-orm软件包;

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }   from './app.component';
import { Config } from 'ng2-orm'; // ng2-orm/Config won't work either

@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

细节

我正在努力构建自己的TS库,以用于angular2和ionic2。我已经进行了研究和搜索,似乎无法想出失败的原因,这可能只是由于我的某种不完整。

我知道这仅仅是个开始,但是我可以想象从项目内部导出的任何内容都应该可以访问。我可能需要一个ngModule定义吗?

我提供了package.json,一些文件夹结构,gulp(所以您可以看到它)和tsconfig.json

一切都可以编译等。

但是,当我在有角度的快速入门上安装它时,它说我尝试导入时找不到ng2-orm。我将所有内容存储在index.js中,并且程序包在node_modules文件夹中。

我是否缺少systemjs.config.js需要的东西?我不确定。我有一个types.json,但它基本上是空的,也许我在那里缺少什么?

索引

export * from './Config/Config';

配置/配置

export class Config {
  public test(): boolean { return true; }
}

定义文件

索引

export * from './Config/Config';

配置文件

export declare class Config {
    test(): boolean;
}

package.json

{
  "name": "ng2-orm",
  "version": "0.0.1",
  "description": "An Angular2 ORM style data modeler to make your life easier for data management and versioning.",
  "main": "dist/js/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "typings": "./dist/definitions/**/*.d.ts",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/ArchitectNate/ng2-orm.git"
  },
  "keywords": [
    "ng2",
    "angular2",
    "ionic2",
    "ORM",
    "SQLite",
    "WebSQL"
  ],
  "author": "Nathan Sepulveda <[email protected]>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/ArchitectNate/ng2-orm/issues"
  },
  "homepage": "https://github.com/ArchitectNate/ng2-orm#readme",
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-typescript": "^3.0.1",
    "merge2": "^1.0.2",
    "tslint": "^3.15.1",
    "typescript": "^2.0.3",
    "typings": "^1.4.0"
  }
}

资料夹结构

在此处输入图片说明

gulpfile.js

我包括了这个,所以您可以看到我的gulp在dist / js,dist / definitions和dist / maps中放置了代码

var gulp = require('gulp');
var ts = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var merge = require('merge2');

var tsProject = ts.createProject('tsconfig.json');

gulp.task('scripts', function() {
  var tsResult = tsProject.src()
    .pipe(sourcemaps.init())
    .pipe(tsProject());

  return merge([
    tsResult.dts.pipe(gulp.dest('dist/definitions')),
    tsResult.js
      .pipe(sourcemaps.write('../maps'))
      .pipe(gulp.dest('dist/js'))
  ]);
});

gulp.task('watch', ['scripts'], function() {
  gulp.watch('./src/**/*.ts', ['scripts']);
});

gulp.task('default', ['scripts', 'watch']);

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "outDir": "dist/js",
    "declaration": true
  },
  "filesGlob": [
    "src/**/*.ts",
    "!node_modules/**/*"
  ],
  "exclude": [
    "node_modules",
    "typings/global",
    "typings/global.d.ts"
  ],
  "compileOnSave": true,
  "atom": {
    "rewriteTsconfig": false
  },
  "scripts": {
    "prepublish": "tsc"
  }
}
布鲁诺·格里德(Bruno Grieder)

对于您的ng2-orm图书馆,请尝试将typings输入package.jsonindex.d.ts,这会重新导出所有内容,例如

"typings": "./dist/definitions/index.d.ts"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章