'Cannot find module 'atptest' or its corresponding type declarations.ts(2307)

I have created an angular library using angular cli. I can use it locally but when I publish it to npm, I cannot use it in any angular application.

I install my published library using the following command and it installs without any problems:

npm i atptest

Here is how I want to import the module:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AtptestModule } from 'atptest';
import { AppComponent } from './app.component';

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

However, it unfortunately does not work and throws the following error:

Cannot find module 'atptest' or its corresponding type declarations.ts(2307)

Here is the complete source code for the library:

https://github.com/atoraby/atptest

Could anybody try to install this package and tell me what should I do to fix the problem? I guess there is a kind of configuration that I have missed. what does corresponding type declarations.ts mean?



Solution 1:[1]

Check that your package has been installed alongside all other packages in node_modules directory (usually at the root of the project) and that you haven't created some nested node_modules directory hierarchy (by running npm install in any other than the root dir).

I gave it a try and installed the package. The actuall code is not pushed into your github repo yet, but by browsing into the node_modules folder I figured out that the actual location where your AtptestModule is located, is the following: atptest/projects/atptest/src/lib/atptest.module and this is related to the structure of your project.

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick Papadiochos