-
Notifications
You must be signed in to change notification settings - Fork 57
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
openapi-generator does not generate ESM support for Java Script files #5156
Comments
Hi @ch-sap , Thanks for raising this. It appears that the default tsconfig compiler options we’re using don’t account for the Meanwhile, to generate ESM enabled code, you can do the folowing:
Hope this helps. |
Dear deekshas8, I changed the command to: "npm ci && npx openapi-generator --input external_resources/PRINTAPI.json --outputDir srv/external --tsconfig tsconfig.json --generateESM true --transpile true --overwrite && npx openapi-generator --input external_resources/FORMSAPI.json --generateESM true --outputDir srv/external --transpile true --overwrite" I added a tsconfig.json: The error I get is: Cannot find module '@sap-cloud-sdk/openapi'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? When I set the moduleResolution to nodenext, I get other errors: .../node_modules/undici-types/index.d.ts:35:1759 - error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path. Best regards, |
Hi @ch-sap, You're missing the |
I have as a dependency: I changed: tsconfig: Still the same error. It does not accept openapi as module: |
Hi @ch-sap , I found the issue. You need to set module to
We will release a new minor version soon. |
Describe the bug
We have a CAPJS project that is from type module (ESM enabled). We try to generate for this project, the Forms Service by Adobe API based on the Json from Business API Hub with the openapi-generator.
We found that there is an option "generateESM". We set this to true. Unfortunately, the option does not change the generated coding.
npx openapi-generator --input external_resources/FORMSAPI.json --generateESM false --outputDir srv/external --transpile true --overwrite
When we use the generated files in our module, we get informed that it is CommonJS, which cannot be used. Could you please check?
Error: This file is being treated as an ES module because it has a '.js' file extension and '/home/user/projects/partner-reference-application/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
import {
StoreFormTemplatesApi }
from'../../external/FORMSAPI/store-form-templates-api.js';
To Reproduce
Steps to reproduce the behavior:
Expected behavior
We expect that the esm code can be used.
The text was updated successfully, but these errors were encountered: