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

TypeGen: Schema generation fails with nodenext TypeScript module resulution naming scheme (.js for ts files) #6245

Closed
james-camilleri opened this issue Apr 7, 2024 · 1 comment

Comments

@james-camilleri
Copy link

james-camilleri commented Apr 7, 2024

Describe the bug

Running the sanity schema extract command fails when using the modern NodeNext module resolution in TypeScript. NodeNext resolution (which is required for correctly loading/recognising package.json export maps) requires *.ts files to be written with a *.js extension, as TypeScript doesn't rewrite paths as part of the compilation process. This extension mismatch causes the schema extract command to fail with a Cannot find module error.

To Reproduce

Steps to reproduce the behavior:

  1. Create a new TypeScript Sanity project.
  2. Set the "type" in package.json to "module".
  3. Change the "module" and "moduleResolution" fields in tsconfig.json to `"NodeNext"
  4. Correct the arising TypeScript errors related to .js extensions.
  5. Run sanity schema extract.
  6. The extraction process will fail to find the .js modules.

A starter project showing this issue has been created here:
https://github.com/james-camilleri/sanity-typegen-reproduction

The commit showing the config to reproduce is here:
james-camilleri/sanity-typegen-reproduction@7e70266

Expected behavior

Schema generation should work as expected with older resolution mechanisms.

Which versions of Sanity are you using?

@sanity/cli (global)          3.36.4 (up to date)
@sanity/eslint-config-studio   4.0.0 (up to date)
@sanity/vision                3.36.4 (up to date)
sanity                        3.36.4 (up to date)

What operating system are you using?
Windows 10.

Which versions of Node.js / npm are you running?

npm -v && node -v
10.5.0
v21.7.2
@bjoerge
Copy link
Member

bjoerge commented Apr 9, 2024

You're probably better off using moduleResolution: "bundler", it's like moduleResolution: "nodenext" but doesn't have the drawbacks that comes with nodenext, i.e. it doesn't require .js extensions.

@bjoerge bjoerge closed this as completed Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants