首页 > 解决方案 > JS + DharmaProtocol - 未捕获的语法错误:请求的模块“...”不提供名为“Dharma”的导出

问题描述

我正在使用 Dharma 协议构建中继器。尝试导入协议时(通过 yarn add @dharmaprotocol/dharma.js 安装)我收到错误:

Uncaught SyntaxError: The requested module 
'./node_modules/@dharmaprotocol/dharma.js/dist/lib/src/index.js' does not 
provide an export named 'Dharma'

我尝试将位于“node_modules/@dharmaprotocol/dharma.js/dist/lib/src/”目录中的 index.js 文件重命名为 index.mjs,希望 JS 将其识别为模块文件,但没有成功。

mint.js:

import { Dharma } from "@dharmaprotocol/dharma.js";
const provider = window.web3.currentProvider;
provider.enable();
const dharma = new Dharma(provider);

index.js:

"use strict";
/***********
 *  Utils  *
 ***********/
Object.defineProperty(exports, "__esModule", { value: true });
// Allows the user to instantiate the correct version of BigNumber.js 
without
// needing to add version 5.0.0 to their project.
var bignumber_1 = require("../utils/bignumber");
exports.BigNumber = bignumber_1.BigNumber;
var Web3 = require("web3");
exports.Web3 = Web3;
/***********
 *  Types  *
 ***********/
var dharma_1 = require("./types/dharma");
exports.Dharma = dharma_1.Dharma;

标签: javascriptdependenciesethereum

解决方案


推荐阅读