Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with Node16/NodeNext moduleResolution #1200

Open
AsyncBanana opened this issue Dec 29, 2023 · 4 comments
Open

Fix compatibility with Node16/NodeNext moduleResolution #1200

AsyncBanana opened this issue Dec 29, 2023 · 4 comments
Labels

Comments

@AsyncBanana
Copy link

When setting ModuleResolution to NodeNext in a project's tsconfig.json and using ESM within that project, superstruct's types fail to be discovered. I am fairly sure this is due to the fact that index.d.ts imports other type declarations without file extensions.

It would be a fairly simple fix to change imports to use .js file extensions, which do work, even for type declarations, and shouldn't break anything.

@mnahkies
Copy link

mnahkies commented Jan 9, 2024

Duplicates #1160

Would be nice to get a resolution to this / #1160 - just ran into this today 🤞

@ciscoheat
Copy link

Same here, cannot integrate Superstruct in Superforms v2 due to this.

@ciscoheat
Copy link

Opened a PR for this issue in #1211

@arturmuller arturmuller pinned this issue Mar 11, 2024
@arturmuller arturmuller changed the title Types incompatible with NodeNext moduleResolution Fix compatibility with Node16/NodeNext moduleResolution Mar 11, 2024
@nerochiaro
Copy link

I am testing version 1.0.5-0 which, as I understand it, is a pre-release for the fix to this issue.
It works OK if I put "moduleResolution":"node16" in my tsconfig.json.

However it seems to fail for me when I also use "module": "node16" along with it.
This is what is recommended for node 20 by https://www.npmjs.com/package/@tsconfig/node20 so I would expect superstruct to work with this common configuration. But maybe I am misunderstanding something.

My index.ts file is like this:

import { object, string } from 'superstruct';
const User = object({ foo: string() });

and I get this error:

index.ts:1:32 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("superstruct")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/home/ugo/superstructure-test/package.json'.

1 import { object, string } from 'superstruct';

Am I missing something or should this work too ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants