2

See the following import:

import { publishObjectAsync, consumeObjectsAsync, createChannelAsync } from "../shared/messaging/rabbitmq" 

Which produces this error:

SyntaxError: The requested module does not provide an export named 'publishObjectAsync'

What's going on?

2 Answers 2

1

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!!!!!

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).

That was the issue. It supports alisaes all the way!

Sign up to request clarification or add additional context in comments.

7 Comments

Does that mean the target file was being processed with Babel or something you mean? Or was it ES6 import syntax in a .js file? Wouldn't that throw a syntax error?
@loganfsmyth Not anymore, I'm using --experimental-modules. It's Node's native ES2015 modules.
@loganfsmyth Yeah you know I was using Babel, but I switched to --experimental-modules and my fault was I renamed all file extensions to .mjs but I forgot to do it in a dependent project so I was loading CJS modules from ES modules.
Yeah I'm just confused because you said import { publishObjectAsync } from worked, which shouldn't be the case for CommonJS. Was that also not working?
@loganfsmyth If the imported module is CJS it won't work with named imports
|
0

The syntax you used for aliases is right - so I would assume experimental ES Module loading does not support importing specific exports with aliases.

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.

2 Comments

Appears to be the case. Here's the commit which has test cases for import * and import default but I don't see one for import { x as y } which presumably backs up the assumption that this isn't implemented as yet
See my own answer, thank you anyway for the effort! And yeah, an aliased wildcard import would've been the workaround.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.