[英]Cannot import custom npm package by package name
I'm loosely following this tutorial to create my own angular npm package called customlib
so I can manage dependencies across my projects without making them public on npm. 我正在松散地遵循本教程来创建我自己的有角度的npm包,称为customlib
这样我就可以管理项目中的依赖项,而不必在npm上公开它们。
in my app.module.ts
I get a module not found: Can't resolve 'customlib'
error when I do the following: 在我的app.module.ts
中,我app.module.ts
module not found: Can't resolve 'customlib'
执行以下操作时module not found: Can't resolve 'customlib'
错误:
import { customModule } from 'customlib';
it works fine if I do this though: 如果我这样做,它会很好:
import { customModule } from '../../node_modules/customModule/dist-lib/index';
Is there something I'm missing? 有什么我想念的吗? it's worth noting that I move all files I want to include in my package to the dist-lib
directory. 值得注意的是,我将要包含在包中的所有文件都移到了dist-lib
目录中。
My library's package.json
looks like this: 我库的package.json
看起来像这样:
{
"name" : "customlib",
"version" : "0.1.0",
"private" : true,
"dependencies" : [
...
],
"files" : [ "dist-lib/" ],
"repository" : {
"type" : "git",
"url : "path/to/repo"
},
"types": "dist-lib/index.d.ts"
}
I'm adding the dependency in the consumer project's package.json
as so: 我将依赖项添加到使用者项目的package.json
如下所示:
"customlib" : "path/to/repo"
And I've also added the following to the consumer project's tsconfig.json
: 而且我还将以下内容添加到使用者项目的tsconfig.json
:
"include": [
"src/**/*.ts",
"node_modules/customlib/dist-lib/index.ts"
]
Try on consumer package.json dependencies: 尝试使用消费者package.json依赖项:
"customlib" : "file:path/to/repo"
And not forget "npm install". 并且不要忘记“ npm install”。
I found a resource that was published by angular team that describes about creating a angular package . 我找到了由角度小组发布的资源,其中描述了有关创建角度包的信息 。 And in here you can fin some examples as well as some packaging libraries. 在这里,您可以找到一些示例以及一些打包库。
Please go through this document. 请仔细阅读本文档。 Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.