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

Possible ESM issue when running sanity typegen extract #6998

Open
heggemsnes opened this issue Jun 20, 2024 · 0 comments
Open

Possible ESM issue when running sanity typegen extract #6998

heggemsnes opened this issue Jun 20, 2024 · 0 comments
Labels
bug typegen Issues related to TypeScript types generation

Comments

@heggemsnes
Copy link

heggemsnes commented Jun 20, 2024

Describe the bug

We've setup a kinda config based routing system on Next.js (so we can use less time refactoring all our files when you change your preview...). We want to use some data from here to i.e. give a nice preview of the path in the slug or add a "copy" link to the frontend URL.

When doing this and running cd sanity && dotenv -e ../.env -- sanity schema extract --path ../schema.json --enforce-required-fields it fails and produces an error:

✖ Failed to extract schema, with enforced required fields

/project/workspace/node_modules/.pnpm/next-safe-action@7.0.2_next@14.2.1_react-dom@18.2.0_react@18.2.0_zod@3.23.8/node_modules/next-safe-action/dist/hooks.mjs:4
import { isNotFoundError } from "next/dist/client/components/not-found.js";
^^^^^^
SyntaxError: Cannot use import statement outside a module
    at Object.newLoader [as .mjs] (/project/workspace/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.21.5/node_modules/esbuild-register/dist/node.js:2262:9)
    at Object.<anonymous> (/project/workspace/app/client.component.tsx:2:27)
 ELIFECYCLE  Command failed with exit code 1.

Note that this seems to have started happening after we began to use next-safe-action so it might be the problem is there?

To Reproduce

Steps to reproduce the behavior:

  1. Check reproduction here
  2. Run pnpm typegen in the console.

Expected behavior

Would hope that we can get it to work as the next-safe-actions is quite useful :)

Which versions of Sanity are you using?

@sanity/cli (global) 3.47.1 (up to date)
sanity 3.47.1 (up to date)

What operating system are you using?
Sandbox (?)

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

9.8.1
v20.9.0

Additional context

In our actual project we are not getting this exact error but something similar:

/Users/sigurdheggemsnes/Documents/GitHub/home-start/node_modules/.pnpm/next-safe-action@7.0.2_next@14.2.3_react-dom@18.3.1_react@18.3.1_zod@3.23.8/node_modules/next-safe-action/dist/index.mjs:2
import { validate } from "@typeschema/main";
^^^^^^
SyntaxError: Cannot use import statement outside a module
    at Object.newLoader [as .mjs] (~/Documents/GitHub/home-start/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.21.4/node_modules/esbuild-register/dist/node.js:2262:9)
    at Object.<anonymous> (~/Documents/GitHub/home-start/src/server/actions/safe-action.ts:1:40)
    
@sgulseth sgulseth added bug typegen Issues related to TypeScript types generation labels Jun 24, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug typegen Issues related to TypeScript types generation
Projects
None yet
Development

No branches or pull requests

2 participants