Open TheAsda opened 2 weeks ago
If i remove "exports" section from ts-rest's package.json everything works fine
Looks like ts-rest has some weird bundling and "import" field in "exports" actually reexports cjs module as esm thus iitm fails to parse exported modules and proxies zero exports
I found a workaround:
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const core = require('@ts-rest/core');
const { initContract } = core;
Looks like the issue comes from parsing exported modules. If you launch without iitm hook it loads cjs version of package then mjs. iitm parses wrong export and produces wrong virtual proxy file for the library
Looks like for some reason iitm treats package as cjs even though it has esm export
for some reason iitm treats package as cjs even though it has esm export
Loader hooks (including iitm) load ESM and CJS loaded via ESM modules.
iitm v1.8.1 has been released. Have you tried that yet?
I'll try later today
Still error but this time with more details
Here is the reproduction brand https://github.com/TheAsda/iitm-ts-rest-issue/tree/v1.8.1
The ".cjs.mjs" file reexports cjs module with export
If i replace "import" section with actual esm file different error occurs.
So the ".esm.js" file is an actual esm module that exports a bunch of properties
But it's being treated as cjs module for some reason
And the behavior when i remove "exports" from the package's package.json and app works fine persists
Currently i found a "fix" what temporarily fixes. I'm patching @ts-rest/core
package with yarn patch
and put cjs entrypoint to the "import" and using dynamic import()
.
It looks weird but works)
I'm using the ts-rest library. Without iitm it works just fine, but when i add iitm with
register
or--loader
it throwsSyntaxError: The requested module '@ts-rest/core' does not provide an export named 'initContract'
.Steps to Reproduce the Problem
Here is the reproduction repo. There are three scripts:
register
callSpecifications
Library version: 1.8.0 Node version: 20.11.1