请参阅以下import
:
import { publishObjectAsync, consumeObjectsAsync, createChannelAsync } from "../shared/messaging/rabbitmq"
产生此错误:
SyntaxError:请求的模块未提供名为的导出 'publishObjectAsync'
发生了什么事?
答案 0 :(得分:1)
哎呀,对不起,这是我的错,但我相信提供我自己的答案是值得的,所以其他人可能会遇到同样的问题,他们可以得到一个提示!
/shared
中的代码文件扩展名未重命名为.mjs
!!!!!
因此,如果您发现此问题,则应检查目标模块中是否存在导出,或者导入的模块是否具有Michael Jackson文件扩展名(.mjs)。
这就是问题所在。它一直支持alisaes!
答案 1 :(得分:0)
您用于别名的语法是正确的 - 所以我假设实验性ES模块加载不支持使用别名导入特定导出。
您可以尝试使用别名加载所有导出:
import * as rabbitmq from "rabbitmq";
export const createChannelAsync = () => rabbitmq.createChannelAsync(createConnectionAsync);
或者您可以尝试导出语法是否支持别名。
export { name1 as default, … };
有关语法的详细信息,请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import和https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export。