swagger-api / swagger-js

Javascript library to connect to swagger-enabled APIs via browser or nodejs
http://swagger.io
Apache License 2.0
2.61k stars 759 forks source link

react-native Error: Unable to resolve module @swagger-api/apidom-reference/configuration/empty #3411

Closed voydz closed 4 months ago

voydz commented 5 months ago

Q&A (please complete the following information)

Content & configuration

Swagger/OpenAPI definition:

# take any example swagger 2.0 spec

Swagger-Client usage:

SwaggerClient({
  spec: './spec.json',
})

Describe the bug you're encountering

upon using newer versions of swagger-client >= 19 the following error will prevent the usage in react-native

Error: Unable to resolve module @swagger-api/apidom-reference/configuration/empty from <app>/node_modules/swagger-client/lib/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js: @swagger-api/apidom-reference/configuration/empty could not be found within the project or in these directories:
  node_modules/swagger-client/node_modules

To reproduce...

Steps to reproduce the behavior: (setup of react-native is required)

  1. npx react-native@latest init SwaggerTest --pm npm --install-pods false

  2. npm i swagger-client

  3. import swagger client in App.tsx import SwaggerClient from 'swagger-client';

  4. add the following code block to the top of the App component

    const client = new SwaggerClient({
    spec: 'https://petstore.swagger.io/v2/swagger.json',
    });
  5. start react-native npm start and launch any app i.e. by pressing 'a' in the react-native cli

Expected behavior

app should initialize swagger-client without error

Additional context or thoughts

issue may be related to #3136

char0n commented 4 months ago

Hi @voydz,

According to this article, React Native supports exports fields since v0.72. Some of swagger-client dependencies also use imports package.json field as well.

If the swagger-client still doesn't work for you, you can try using UMD build:

import SwaggerClient from 'swagger-client/dist/swagger-client.browser.js'

Hope it helped a bit.