So I want to publish a typescript module.
I depend on some node resources: node-fetch & file-type.
I have played with a variety of settings to get imports to work across the board, but I haven’t figured it out.
Current state:
package.json:
"type": "module"
tsconfig.json:
"module":"ESNext",
"esModuleInterop": false,
In this mode, my attempt to import my dependencies simply fails.
Turning the interop to true doesn’t make a difference.
If I set "module":"commonjs"
Then I can import my dependencies, but nobody can see my exports:
import { caption } from "@m87/mdc-ts";
^^^^^^^
SyntaxError: The requested module '@m87/mdc-ts' does not provide an export named 'caption'
And yet, when I look at the output of the typescript build, I see:
const caption = async (file) => {
// Code would be here
};
exports.caption = caption;
My test file is also set with "type":"module"
in it’s own package.json.
Now, if I wasn’t importing those resources, I could publish my module successfully, by removing the "type":"module"
from package.json in my module package — everything is successfully exported!
However, in that case, the resources I need are imported via require
— which those packages do not support.
I feel like I have tried every mix-n-match set of options, including targeting other versions of javascript, switching the interop for all variations… and in the end I’m stumped.