[英]Does experimental ES Module loading in NodeJS support importing named exports?
See the following import
:请参阅以下import
:
import { publishObjectAsync, consumeObjectsAsync, createChannelAsync } from "../shared/messaging/rabbitmq"
Which produces this error:产生此错误:
SyntaxError: The requested module does not provide an export named 'publishObjectAsync' SyntaxError: 请求的模块不提供名为“publishObjectAsync”的导出
What's going on?这是怎么回事?
Oops, sorry, It was my fault but I believe that it's worth the effort providing my own answer so others may encounter the same problem and they can get a hint!哎呀,对不起,这是我的错,但我相信提供我自己的答案是值得的,这样其他人可能会遇到同样的问题,他们可以得到提示!
The code file extensions within /shared
weren't renamed to .mjs
!!!!! /shared
中的代码文件扩展名没有重命名为.mjs
!!!!!!
So, if you find this issue you should check if the export exists in the target module or if the imported module has the Michael Jackson file extension (.mjs).因此,如果您发现此问题,您应该检查导出是否存在于目标模块中,或者导入的模块是否具有 Michael Jackson 文件扩展名 (.mjs)。
That was the issue.这就是问题所在。 It supports alisaes all the way!它一直支持别名!
The syntax you used for aliases is right - so I would assume experimental ES Module loading does not support importing specific exports with aliases.您用于别名的语法是正确的 - 所以我假设实验性 ES 模块加载不支持导入带有别名的特定导出。
You could try to load all exports with an alias, though:不过,您可以尝试使用别名加载所有导出:
import * as rabbitmq from "rabbitmq";
export const createChannelAsync = () => rabbitmq.createChannelAsync(createConnectionAsync);
Or you could try if the export syntax supports aliases.或者您可以尝试导出语法是否支持别名。
export { name1 as default, … };
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export for further information on the syntax.请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import和https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements /export以获取有关语法的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.