[BUG] Module does not provide an export
I am migrating our frontend to use Vite. We are using the OpenAPI generator Axios client to generate all our API code from a specification.
I have generated the code again, and see it in the target folder. Afterwards, I am building it using npm and a dist folder appears. Then I am adding it as a local import in my package.json file and install it. It's the same as it was before.
"restClient": "file:src/api/generated-sources" When I start the Vite dev server, for some reason I am getting below error:
Uncaught SyntaxError: The requested module '/src/api/generated-sources/dist/index.js' does not provide an export named 'SortParams' (at HomeView.vue:6:3) I am using this enum in my code without any errors being shown. Only when running the server it throws an error.
This is the enum, in the generated file:
/** *
- @export
- @enum {string} */ export declare enum SortParams { CreationDatetime = "CREATION_DATETIME", ModificationDatetime = "MODIFICATION_DATETIME", Process = "PROCESS", Status = "STATUS" } Above is coming from a file called api.d.ts, which is generated. There's also a javascript file called api.js, which is built so it's a bit hard to read. A cmd+f reveals that the SortParams enum is present there and seems to be exported.
This is how I am importing it in my HomeView:
import { CaptureCaseSortParams, CaptureCaseStatus, Configuration, DocumentCaptureCasesApi, PaginationData, SortOrder, } from 'restClient'; The error is already being thrown at the line of the import.
This is my openapitools.json file:
{ "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", "spaces": 2, "generator-cli": { "version": "5.3.0", "useDocker": true,
"generators": {
"v1": {
"generatorName": "typescript-axios",
"inputSpec": "src/api/openapi.yml",
"output": "src/api/generated-sources",
"additionalProperties": {
"npmName": "restClient",
"useSingleRequestParameter": true
},
"globalProperty": {
"skipFormModel": false
}
}
}
}
}
Does anyone know what this might be?
I am facing the same issue.
I faced the same issue when passing this additional property to typescript-axios :
withSeparateModelsAndApi=true
Removing this property solved it. It generates a single file api.ts.
(The original problem is caused by Vite in dev mode not bundling the types exported by a module, unless they are explicitly imported with import { type ... }. See https://github.com/vitejs/vite/issues/7226)