api-platform / api-doc-parser

Transforms a Hydra API doc in an intermediate representation that can be used for various tasks such as creating smart API clients, scaffolding code or building administration interfaces.
MIT License
104 stars 71 forks source link

Module not found: Can't resolve 'jsonref' #120

Closed herndlm closed 2 years ago

herndlm commented 2 years ago

Version(s) affected: 0.15.7

Description

Trying to upgrade from 0.15.2 to 0.15.7 gives me the following compilation error in our API platform admin app:

./node_modules/@api-platform/api-doc-parser/lib/esm/openapi3/handleJson.js
Module not found: Can't resolve 'jsonref' in '/usr/src/admin/node_modules/@api-platform/api-doc-parser/lib/esm/openapi3'

I verified that node_modules/jsonref exists. I saw that jsonref was recently added and some importing adaptions were done as well. I don't know much about different JS module types and their imports, but could this be one of the ESM/CJS incompatibilities or something like that?

How to reproduce

sorry, leaving this out for now since I'm not sure yet if this is a bug or not.

Possible Solution

Additional Context

alanpoulain commented 2 years ago

Could you provide a simple reproducer? For instance an application from scratch?

alanpoulain commented 2 years ago

Also make sure jsonref is updated.

alanpoulain commented 2 years ago

I've made the package pure ESM. Please read https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c.

herndlm commented 2 years ago

funny thing, I had to upgrade react-admin from 3 to 4 and @api-platform/admin from 2 to 3 still and after doing that the problem here was also gone. thank you for your effort and help anyways though!

jcubic commented 6 months ago

I'm not able to update @api-platform/admin and @api-platform/api-doc-parser/ updating everything doesn't help. I keep getting error about missing jsonref.

jsonref is installed:

$ yarn build
react-scripts --openssl-legacy-provider build

./node_modules/@api-platform/api-doc-parser/lib/openapi3/handleJson.js
Cannot find module: 'jsonref'. Make sure this package is installed.

You can install this package by running: yarn add jsonref.

$ ls -d node_module/jsonref
node_modules/jsonref

$ yarn list 
...
├─ @api-platform/api-doc-parser@0.16.4
│  ├─ graphql@^16.0.0
│  ├─ inflection@^1.13.0
│  ├─ jsonld@^8.1.0
│  ├─ jsonref@^8.0.0
│  ├─ lodash.get@^4.4.0
│  └─ tslib@^2.0.0
...

How to solve this error?

jcubic commented 6 months ago

I'm not sure if this was the real problem but after installing: @api-platform/api-doc-parser and @api-platform/admin, in yarn list I got two version of jsonref:

$ yarn list ... ├─ @api-platform/api-doc-parser@0.16.4 │ ├─ graphql@^16.0.0 │ ├─ inflection@^1.13.0 │ ├─ jsonld@^8.1.0 │ ├─ jsonref@^8.0.0 │ ├─ lodash.get@^4.4.0 │ └─ tslib@^2.0.0 ├─ jsonref@8.0.8 ...

Installing fixed version of json ref solved the issue:

yarn add jsonref@8.0.0

Note that the library doesn't work when installed. I removed and installed it again and it still throw an error about missing jsonref.