简体   繁体   English

不能在 npm 包中使用别名

[英]cannot use alias in npm package

im trying to create a npm package that i can use in my other app.我正在尝试创建一个可以在我的其他应用程序中使用的 npm 包。 in my development i defined path in tsconfig for importing different modules instead of relative path.在我的开发中,我在 tsconfig 中定义了路径,用于导入不同的模块而不是相对路径。 however, when i download my package in to test app.但是,当我将包下载到测试应用程序中时。 it cannot resolve module path.它无法解析模块路径。

i think if i change to using relative path then it would work.我想如果我改为使用相对路径,那么它会起作用。

in my tsconfig, i defined a path like this在我的 tsconfig 中,我定义了这样的路径

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

in my ts file where i need to import moduleOne i do在我需要导入 moduleOne 的 ts 文件中

import {helper} from "moduleOne"

when i download the package in my other app i get Module not found: Error: Can't resolve 'moduleOne'当我在其他应用程序中下载软件包时,我找不到模块:错误:无法解析“moduleOne”

试试

import { helper } from "moduleOne"

您在导入时缺少 moduleOne 周围的字符串引号。

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

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