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

Nextjs build Failed #352

Closed
mahersalhani opened this issue Jan 4, 2024 · 6 comments
Closed

Nextjs build Failed #352

mahersalhani opened this issue Jan 4, 2024 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@mahersalhani
Copy link

Checking validity of types .Failed to compile.

./node_modules/valibot/dist/index.d.ts:1980:27
Type error: Type parameter declaration expected.

1978 | * @returns A picklist schema.
1979 | */

1980 | declare function picklist(options: TOptions, message?: ErrorMessage): PicklistSchema;
| ^
1981 | /**
1982 | * See {@link picklist}
1983 | *
error Command failed with exit code 1.

I use
"valibot": "^0.25.0",

@fabian-hiller
Copy link
Owner

Can you send me your schema? But it seems like this is an external problem.

@fabian-hiller fabian-hiller self-assigned this Jan 5, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label Jan 5, 2024
@ZilvinasAbr
Copy link

I've got similar issue when trying to use valibot inside of a server action for validating form submission with Next.js app router.

The issue happens when trying to build the next.js application.

Code looks something like this:

'use server'

import { object, parse, string } from 'valibot'

const schema = object({
  name: string(),
})

export const submit = async (formData: FormData) => {
  const parsedFormData = parse(schema, {
    name: formData.get('name'),
  })

  // Rest of the code
}

I get the error when building:

n [ValiError]: Invalid type

...

issues: [
    {
      reason: 'type',
      validation: 'enum',
      origin: 'value',
      message: 'Invalid type',
      input: undefined,
      issues: undefined,
      abortEarly: undefined,
      abortPipeEarly: undefined,
      skipPipe: undefined,
      path: [Array]
    }
  ]

@fabian-hiller
Copy link
Owner

Something seems to be wrong here. A ValiError should only be thrown when validating data, not when bundling your application. Valibot is just a simple JavaScript library that exports some functions. We have no dependencies. So I assume there is a problem in your code, configuration or build process. Feel free to share a minimal reproduction via Stackblitz so I can debug the problem.

@mahersalhani
Copy link
Author

mahersalhani commented Jan 6, 2024

Can you send me your schema? But it seems like this is an external problem.


import { object, string, minLength, toTrimmed, type Output } from 'valibot';

export const DesignFormSchema = object({
  name: string(undefined, [toTrimmed(), minLength(3, 'design.name_required')]),
});

export type DesignFormData = Output<typeof DesignFormSchema>;

When I used "valibot": "^0.19.0" it's worked

@fabian-hiller
Copy link
Owner

What version of TypeScript are you using? picklist, the function in the error messages, uses the const modifier. This is a feature introduced in TypeScript v5. It looks like your build process can't handle it.

Tip: You can remove undefined as the first argument of string.

@mahersalhani
Copy link
Author

mahersalhani commented Jan 7, 2024

I use "typescript": "4.9.4" .
I updated to "typescript": "^5.3.3" and it worked

Thank you :)

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

No branches or pull requests

3 participants