首页 > 解决方案 > 不能在 npm 包中使用别名

问题描述

我正在尝试创建一个可以在我的其他应用程序中使用的 npm 包。在我的开发中,我在 tsconfig 中定义了用于导入不同模块而不是相对路径的路径。但是,当我下载我的包以测试应用程序时。它无法解析模块路径。

我想如果我改为使用相对路径,那么它会起作用。

在我的 tsconfig 中,我定义了这样的路径

"moduleOne": ["./moduleOne/src/index.ts"]

在我需要导入 moduleOne 的 ts 文件中

import {helper} from "moduleOne"

当我在我的其他应用程序中下载包时,我得到 Module not found: Error: Can't resolve 'moduleOne'

标签: javascripttypescriptnpmwebpack

解决方案


尝试

import { helper } from "moduleOne"

推荐阅读