当NPM软件包包含多个名称空间/子模块时,如何进行模块分辨率

发布于 2025-01-31 20:29:10 字数 1198 浏览 3 评论 0原文

我正在使用的一个项目正在使用此软件包:https://www.npmjs.com/package/@ethersproject/abstract-provider 在SDK中,我们正在构建。

安装后,SDK node_modules文件夹包含@ethersProject Directory,其中包含Abstract> Abstract-Provider Directory以及作为其他多个目录,每个目录都使用独立的package.json文件自己的名称空间。

我们在SDK中使用代码如下: import {provider}来自'@ethersproject/atravent-provider'; 而且,这对于基于WebPack的项目效果很好,这些项目会导入我们的SDK(例如使用Create-React-app的React应用程序)。

当我想在一个不使用bundler(例如WebPack)的项目中使用我们的SDK时(例如,使用importmap 在此处启动的非常简单的前端,如下所示: https://github.com/unegma/unegma/rainprotocol__verify-gating ),我们正在遇到错误:

无法解决模块指定符“@ethersproject/Abstract-Provider”。相对引用必须以“/”,“ ./”或“ ../” ../".开始,

我假设这是因为我们的SDK不知道如何解析@ethersproject/atravest--提供者因为Abstract-Provider@ethersProject的子模块(甚至不是模块本身)。

解决这个问题的方法是什么?我们是否需要在我们的SDK根中创建decs.d.t.ts文件,其中包含以下内容:声明模块“@ethersproject/atrackext-provider;或有不同的这样做的方法?

A project I am working with is using this package: https://www.npmjs.com/package/@ethersproject/abstract-provider
within an SDK we are building..

After installation, the SDK node_modules folder contains the @ethersproject directory which contains an abstract-provider directory as well as multiple other directories, each their own namespace with separate package.json files.

We use the code in the sdk as follows:
import { Provider } from '@ethersproject/abstract-provider';
and this works fine for webpack based projects which import our SDK (such as a React app using create-react-app).

When I want to use our SDK in a project which DOESN'T use a bundler such as webpack (such as a very simple frontend pulling in our sdk with importmap as here: https://github.com/unegma/rainprotocol__verify-gating), we are getting an error:

Failed to resolve module specifier "@ethersproject/abstract-provider". Relative references must start with either "/", "./", or "../".

I'm assuming this is because our SDK doesn't know how to resolve @ethersproject/abstract-provider because abstract-provider is a submodule of @ethersproject (which isn't even a module itself).

What is the way to solve this issue? Do we need to create a decs.d.ts file in our SDK root which contains something like: declare module "@ethersproject/abstract-provider; or is there a different way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文