当NPM软件包包含多个名称空间/子模块时,如何进行模块分辨率
我正在使用的一个项目正在使用此软件包: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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论