How to module.exports another module?

webpack is not designed to support emitting ES modules. Its ES module support is for apps that use ES modules internally but emit to a different format. I'd recommend using Rollup instead, which has full native ES module support, but can also support CJS with the same config if you still need it.


I think the problem that you're seeing is because your module has no default export.

export { default as function1 } from 'function1.ts';
export { default as function2 } from 'function2.ts';

This code exposes the default export of function1.ts as function1 and the default export of function2.ts as function2, but it does not provide a default export of its own.

You could try the following instead

import { default as function1 } from "function1.ts";
import { default as function2 } from "function2.ts";

export default { function1, function2 };

Heres a CodeSandbox showing this in action. (My example mixes ts and js, but it shouldn't make a difference for what you're doing here)

Hope that helps!

Tags:

Javascript