Unable to locate the module from my personal library in Typescript

The Query

Why is my ng2-orm package not importing or being recognized by vscode when I try to import Config from '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 { }

Information

I am attempting to create my own TypeScript library for angular2 and ionic2. Despite my efforts in research, I cannot pinpoint why this issue is arising and suspect it may be due to a lack on my end.

While I understand it's just the beginning, I assume that anything exported within the project should be accessible. Could there be an ngModule definition that I'm overlooking?

I have included the package.json, folder structure, gulp setup (for reference), and tsconfig.json

All seems to compile fine.

However, upon installing it in the angular quickstart, it reports a failure to locate ng2-orm during import. All files are consolidated into index.js, and the package resides in the node_modules directory.

Is there something required by systemjs.config.js that I'm missing? My typings.json file is essentially empty – could I be omitting something here?

index.ts

export * from './Config/Config';

Config/Config.ts

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

Definition Files

index.d.ts

export * from './Config/Config';

Config.d.ts

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 <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="315f504559505f42714559544159415457575452451f525e5c">[email protected]</a>>",
  "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"
  }
}

Directory Setup

https://i.sstatic.net/BHo3X.png

gulpfile.js

This code snippet demonstrates how my gulp organizes code into dist/js, dist/definitions, and dist/maps directories

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"
  }
}

Answer №1

To improve your ng2-orm library, consider updating the typings entry in your package.json to reference index.d.ts, which will re-export all definitions.

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way for me to manually manipulate the advancement of the progress bar from @ngx-progressbar/core in Angular5/Ionic4?

I've been working on implementing a progress bar into my application using the @ngx-progressbar/core library. However, I'm facing an issue where I can't seem to control its progress effectively. Whenever I try to increase the progress increm ...

Utilizing the Loess npm module in conjunction with Angular 4

I am attempting to incorporate the Loess package into my project. The package can be found on NPM and offers various regression models for data fitting. I successfully installed it using npm install loess --save, and it now resides in the node_modules dire ...

When trying to incorporate aws-sdk into Angular2, an error message stating "Module 'stream' cannot be found" may occur

I encountered the following issues: Error TS2304: Cannot find name 'Buffer', https://github.com/aws/aws-sdk-js/issues/994 and Using aws-sdk with angular2 Even though my typings and @types/node seem to be properly installed, I am still encount ...

When utilizing a SSL certificate generated by Let's Encrypt in Node.js, the socket fails to establish a connection

I have set up an https server using a certificate generated with lets encrypt. My goal is to establish a connection between the Socket.io client and the Socket.io server linked to the https server. Unfortunately, the socket keeps disconnecting without any ...

Tips for Effectively Declaring a Variable with React's useState

How should I correctly specify variable types in useState? In the code below, the value for alert must be either "success","warning", "error", or "info" const [alertValue, setAlertValue] = useState("error" ...

Problem with overlapping numbers in the Vis network

I am currently working on a project using Angular 8 and Visnetwork. Everything is going well, but I am facing an issue with overlapping numbers on lines. Is there a way to adjust the position of the numbers on one line without separating the lines? Can s ...

What is the best way to ensure the website theme remains consistent after a refresh in React?

I am currently enhancing a weather forecast website by incorporating a theme toggler feature. The functionality has been successfully implemented, but I am facing an issue where the selected theme does not persist after reloading the page. Can someone he ...

How to access a static TypeScript variable in Node.js across different files

I encountered a situation like this while working on a node.js project: code-example.ts export class CodeExample { private static example: string = 'hello'; public static initialize() { CodeExample.example = 'modified'; } ...

Encountering TypeScript error in the beforeRouteUpdate hook with Vue and vue-property-decorator

I am developing an application using Vue 2 with TypeScript and vue-property-decorator. Within my component, I am utilizing the beforeRouteEnter/beforeRouteUpdate hooks. One of the methods in my component is findProjects, which I want to call within the bef ...

Can you explain the significance of having two consecutive => symbols?

While I understand lambdas and function types, I am unsure about the following expression: displayFunc: (string) => string = x => x; I find the two symbols "=>" puzzling. Can someone explain what this means? ...

Issue encountered when utilizing TypeORM within NestJS: Unable to import Entity Repository

Issue with EntityRepository Import Despite having @nestjs/typeorm installed, VS Code is not recognizing the decorator I need to use. Any suggestions on how to resolve this? ...

Ways to display notifications when the user is not actively browsing the website?

How can websites display notifications even when the user is not actively on the site? Take Facebook messenger, for instance. Even with the page closed, notifications still pop up. The same goes for Twitter, which also sends push notifications. I ...

Suggestions for importing by Typescript/VS Code

Imagine you have a file called a.ts that contains 4 named imports: export const one = 1 export const two = 2 export const three = 3 export const four = 4 Next, you have a file named b.ts and you want to import some variables from a.ts. import {} from &a ...

Guide to utilizing the sendEmailVerification() functionality in Angular

I'm currently working on setting up an email verification system using Angular and the Google Firebase API. I came across the sendEmailVerification() function through this reference, but I'm a bit unsure about how to correctly implement it. To ad ...

The creation of the Angular project was unsuccessful, with the error message "npm ERR! path AngularappTwo ode_modulesacorninacorn" causing the issue

These are the steps I took to create my first Angular application: First, I installed NodeJS Next, I installed VSCode I then checked my NodeJS and npm versions https://i.stack.imgur.com/lj6pI.png After that, I ran the command npm install -g @angular/c ...

Is there a way to modify the style when a different rarity is selected in Next.JS?

Is there a way to change the style depending on the rarity selected? I am currently developing a game that assigns a random rarity upon website loading, and I am looking to customize the color of each rarity. Here is how it appears at the moment: https:/ ...

Combining Angular with WordPress

I need to integrate an Angular ticket sales form onto the main page of my Wordpress site. What is the best method for accomplishing this? Should I consider using an iframe tag or are there other solutions that may be more effective? Thank you for your as ...

The function jquery__WEBPACK_IMPORTED_MODULE_4__.hubConnection is not recognized

I am currently trying to integrate singlar (not ASP.Core) with angular 8. If I directly include signalr and jQuery in index.html as follows: <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWS ...

The issue of declaration merging and complications with nested node_modules

Here is the structure I am working with: @my/app node_modules @types/angular @types/angular-translate @my/library node_modules @types/angular The issue arises from the fact that @types/angular-translate extends the definitions of @types/angular ...

Are there any methods within Angular 2 to perform Angular binding within a string?

When creating an HTML template with routing, such as shown below: <ul class="sb-sub-menu"> <li> <a [routerLink]="['clientadd']">Client Add</a> </li> </ul> It functions as expected. However, w ...