Module not found: Can't resolve './client'
Description When using code generated by @hey-api/openapi-ts, I'm encountering a module resolution error. The generated code imports from a ./client module that doesn't exist.
Steps to reproduce
Configure @hey-api/openapi-ts with the provided config file
Run the openapi-ts to generate sdk
Import and use the generated code in a project
run the project
Error
Module not found: Can't resolve './client'
1 | // This file is auto-generated by @hey-api/openapi-ts
2 |
> 3 | import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from './client';
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 | import type { ClientOptions } from './types.gen';
5 |
6 | /**
Configuration
// openapi-ts.config.ts
import { defaultPlugins, defineConfig } from '@hey-api/openapi-ts';
export default defineConfig({
input: 'http://localhost/api/swagger/openapi.json',
output: {
format: 'prettier',
lint: 'eslint',
path: './src/client',
},
plugins: [
...defaultPlugins,
{
bundle: true,
name: '@hey-api/client-axios',
runtimeConfigPath: './src/requestSetting.ts',
},
{
enums: 'typescript',
name: '@hey-api/typescript',
},
{
name: '@hey-api/schemas',
type: 'json',
},
{
asClass: true,
serviceNameBuilder: '{{name}}',
name: '@hey-api/sdk',
},
'@hey-api/sdk',
'@tanstack/react-query',
],
});
Please correct me if there is any wrong configuration
@cheehong1030 I see the folder in your screenshot, is it empty?
No, The contents of the folder are normal and there are no typescript errors. But seem he can't find the ./client folder. Is this error about typescript configuration?
Probably! Please create a reproducible example if you want me to have a look
Try this http://github.com/cheehong1030/example-openapi-ts
Can you try with bundleSource_EXPERIMENTAL?
New error Seems this error from the bundle configuration
I observed that when I manually edited the source of the generated client and changed line 4:
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from './client'
into
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from './client/index.cjs'
or
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from './client/index.d'
then I was able to use the functions. However I have no idea if this is correct or just some pure accident - I don't write typescript code on a daily basis
I did notice that inside the client directory there was index.d.ts (that's why I used it) which was a bit surprising as I was expecting an index.ts file
@toudi Hey if it works, it works. I definitely need to improve this feature, just haven't prioritised it
I'm going to close this issue as part of 0.73.0 where clients will be bundled by default. Please let me know if you still run into any problems!