What steps will reproduce the bug?
git clone https://github.com/dandv/lib-does-not-provide-export-foo
cd lib-does-not-provide-export-foo/use-lib
node use-it.js # node v13.9.0
What is the expected behavior?
The script should run and output foo.
What do you see instead?
import { foo } from '../lib/index.js';
^^^
SyntaxError: The requested module '../lib/index.js' does not provide an export named 'foo'
Additional information
Within the context of a large project, this was a pretty odd mystery, when lib/index.js clearly exports foo. Feel free to have some fun figuring out it (not hard with the minimal repro repo, but imagine the confused looks in a real-world scenario). Solution below.
.
.
.
.
.
.
.
.
.
.
Solution
lib/package.json lacks "type": "module".
Proposal
A clearer error would indicate that the imported file is not a module at all. As it is, the error suggested that other symbols were exported fine, so I kept double checking for typos and what not. This happened during a conversion to TypeScript that involved adding one export. The error made me think the problem was that export; it was not - it was that I forgot to add "type": "module" to package.json.
The full title of the bug would be "Misleading error that module does not provide export when "module" is not in fact a module", but that would have been a spoiler.
What steps will reproduce the bug?
git clone https://github.com/dandv/lib-does-not-provide-export-foocd lib-does-not-provide-export-foo/use-libnode use-it.js # node v13.9.0What is the expected behavior?
The script should run and output
foo.What do you see instead?
Additional information
Within the context of a large project, this was a pretty odd mystery, when
lib/index.jsclearly exportsfoo. Feel free to have some fun figuring out it (not hard with the minimal repro repo, but imagine the confused looks in a real-world scenario). Solution below..
.
.
.
.
.
.
.
.
.
Solution
lib/package.json lacks
"type": "module".Proposal
A clearer error would indicate that the imported file is not a module at all. As it is, the error suggested that other symbols were exported fine, so I kept double checking for typos and what not. This happened during a conversion to TypeScript that involved adding one export. The error made me think the problem was that export; it was not - it was that I forgot to add
"type": "module"topackage.json.The full title of the bug would be "Misleading error that module does not provide export when "module" is not in fact a module", but that would have been a spoiler.