0

I am new to publishing Angular libraries and this is my first humble attempt to publish a lib to NPM called wps-ng https://www.npmjs.com/package/wps-ng.

My Public Api file looks like https://github.com/singkara/wps-js-ng/blob/library_test/projects/wps-ng/src/public-api.ts where I have exported the following:

export * from './lib/wps-ng.service';
export * from './lib/wps-ng.component';
export * from './lib/wps-ng.module';

...

However, when I do npm install wps-ng in a 3rd party Angular 9 application, it fails with the error:

TS2307: Cannot find module 'wps-ng' or its corresponding type declarations.

Although, I am able to use this same library (from the dist folder) in the same project as that of the library itself but not from third party application (from node_modules folder).

Any thoughts on why this could happen?

Thanks in Advance.

2
  • I think you might be missing the module property in your lib's package.json file. It needs to point to the compiled js version of your public_api.ts file. Commented Jul 20, 2020 at 21:59
  • Thanks for the comment, I tried adding the module tag in package.json and pointed it to src/public_api.ts. However, it didn't work. Commented Jul 20, 2020 at 22:08

1 Answer 1

3

I have figured out the issue finally, What I did wrong was, I published the library by running the command npm publish in the library folder.

However, the correct way to do this is by running the following commands:

  1. ng build
  2. cd dist
  3. cd your library name
  4. npm pack
  5. npm publish
Sign up to request clarification or add additional context in comments.

1 Comment

Do you also have to remove the /dist from .gitignore?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.