[英]Cannot import custom npm package by package name
我正在松散地遵循本教程来创建我自己的有角度的npm包,称为customlib
这样我就可以管理项目中的依赖项,而不必在npm上公开它们。
在我的app.module.ts
中,我app.module.ts
module not found: Can't resolve 'customlib'
执行以下操作时module not found: Can't resolve 'customlib'
错误:
import { customModule } from 'customlib';
如果我这样做,它会很好:
import { customModule } from '../../node_modules/customModule/dist-lib/index';
有什么我想念的吗? 值得注意的是,我将要包含在包中的所有文件都移到了dist-lib
目录中。
我库的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"
}
我将依赖项添加到使用者项目的package.json
如下所示:
"customlib" : "path/to/repo"
而且我还将以下内容添加到使用者项目的tsconfig.json
:
"include": [
"src/**/*.ts",
"node_modules/customlib/dist-lib/index.ts"
]
尝试使用消费者package.json依赖项:
"customlib" : "file:path/to/repo"
并且不要忘记“ npm install”。
我找到了由角度小组发布的资源,其中描述了有关创建角度包的信息 。 在这里,您可以找到一些示例以及一些打包库。
请仔细阅读本文档。 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.