简体   繁体   English

已发布的角度库在npmjs上没有导入的模块

[英]Published angular library doesn't has imported modules on npmjs

I want to publish a simple angular library in npmjs. 我想在npmjs中发布一个简单的角度库。 So, the steps i followed was: 所以,我遵循的步骤是:

  1. Created the project: 创建项目:

     ng new my-project 
  2. Created the library: 创建了库:

     ng g library my-lib 
  3. Created a module to the library: 为库创建了一个模块:

     ng g module module1 --project my-lib 
  4. Write some code to the module: 将一些代码写入模块:

  5. Added the library declaration to the public_api.ts file: 将库声明添加到public_api.ts文件中:

     export * from './lib/module1/module1.module'; 
  6. Build and publish the library: 构建和发布库:

     ng build my-lib cd dist/my-lib npm publish 

When i test the library locally it works and the library has the exported module. 当我在本地测试库时它工作,并且库具有导出的模块。

If i run 如果我跑

npm pack

and then import the library with 然后导入库

npm install --save path/to/my-lib.tgz 

in another project, it works and the library has the exported module. 在另一个项目中,它工作,库具有导出的模块。

BUT

when i install the library from the npm repo with 当我从npm repo安装库时

npm install --save my-lib 

the library download and install was ok but it is like the library was empty, so the desired module is missing and if i try to import the module in the project it fails and i get an error saying that the module doesn't exists. 库下载和安装是好的,但它就像库是空的,所以缺少所需的模块,如果我尝试导入项目中的模块失败,我得到一个错误说该模块不存在。

How can i publish the library with the module or the modules that i want to keep available? 如何使用我想要保留的模块或模块发布库?

I solved the problem. 我解决了这个问题。 In the 6th step, run: 在第6步中,运行:

ng build my-lib
cd dist/my-lib
npm pack
npm publish my-lib-0.0.1.tgz

now, it is published and contains everything i needed, and i can run npm install from the npm repo without any issues. 现在,它已发布并包含我需要的所有内容,我可以从npm repo运行npm install而不会出现任何问题。 The solution was simply running the npm pack command before and publish the tgz file instead of the dist file. 解决方案之前只是运行npm pack命令并发布tgz文件而不是dist文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM