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

Exporting type definitions from a "use server" file doesn't work. #106

Closed
dertieran opened this issue Jan 8, 2024 · 0 comments
Closed

Comments

@dertieran
Copy link

dertieran commented Jan 8, 2024

Exporting type definitions from a (top level) "use server" file like this

'use server';

export type Input = number;
export async function world2(x: Input) {
  console.log('hello world 2', x);
}

will produce the following error in development

[h3] [unhandled] H3Error: undefined does not match field "params": [Pattern] of type FunctionExpression
    at addParam (/home/projects/github-7jpzac/node_modules/ast-types/lib/types.js:455:27)
    ... 7 lines matching cause stack trace ...
    at async instantiateModule (/home/projects/github-7jpzac/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:56003:10) {
  cause: Error: undefined does not match field "params": [Pattern] of type FunctionExpression
      at addParam (/home/projects/github-7jpzac/node_modules/ast-types/lib/types.js:455:27)
      at eval (/home/projects/github-7jpzac/node_modules/ast-types/lib/types.js:505:25)
      at builder.from (/home/projects/github-7jpzac/node_modules/ast-types/lib/types.js:503:46)
      at wrapExports (/home/projects/github-7jpzac/node_modules/@vinxi/plugin-directives/plugins/wrap-exports.js:392:53)
      at Object.transform (/home/projects/github-7jpzac/node_modules/@vinxi/plugin-directives/plugins/wrap-exports.js:57:24)
      at TransformContext.transform (/home/projects/github-7jpzac/node_modules/@vinxi/plugin-directives/plugin.js:62:29)
      at Object.transform (/home/projects/github-7jpzac/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:44404:62)
      at async loadAndTransform (/home/projects/github-7jpzac/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:55078:29)
      at async instantiateModule (/home/projects/github-7jpzac/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:56003:10) {
    plugin: 'vite-server-references',
    id: '/home/projects/github-7jpzac/app/inline.tsx',
    pluginCode: "'use server';\n" +
      '\n' +
      'export type Input = number;\n' +
      'export async function world2(x: Input) {\n' +
      "  console.log('hello world 2', x);\n" +
      '}\n'
  },
  statusCode: 500,
  fatal: false,
  unhandled: true,
  statusMessage: undefined,
  data: undefined
}

When I remove the export for the Input type, it works as expected.

nksaraf added a commit that referenced this issue Jan 10, 2024
fixes Exporting type definitions from a "use server" file doesn't work. #106
@nksaraf nksaraf closed this as completed Jan 10, 2024
This was referenced Feb 28, 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