繁体   English   中英

无法通过包名称导入自定义npm包

[英]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.

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