api-platform / create-client

Generate React or Vue.js-based Progressive Web Apps from an Hydra-enabled API. Also support React Native.
https://api-platform.com/docs/client-generator/
MIT License
373 stars 132 forks source link

Custom generators are not working #384

Open misterx opened 7 months ago

misterx commented 7 months ago

API Platform version(s) affected: 3.2.20

Description
When I'm trying to get the custom generator working, it fails with an error stating that BaseGenerator is not exported.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/generators/BaseGenerator' is not defined by "exports" in /app/generator/node_modules/@api-platform/create-client/package.json imported from /app/generator/Generator.js
at new NodeError (node:internal/errors:405:5)
    at exportsNotFound (node:internal/modules/esm/resolve:366:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:713:9)
    at packageResolve (node:internal/modules/esm/resolve:899:14)
    at moduleResolve (node:internal/modules/esm/resolve:973:20)
    at defaultResolve (node:internal/modules/esm/resolve:1193:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:39) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

How to reproduce
Use the following package.json file:

{
  "name": "test-generator",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "@api-platform/create-client": "^0.10.0"
  }
}

Take generator and template from documentation https://api-platform.com/docs/create-client/custom/

Execute:

npm install
npm init @api-platform/client https://demo.api-platform.com/ ../test -- --generator "$(pwd)/Generator.js"

Additional Context

From what I see in the package.json file at https://github.com/api-platform/create-client/blob/main/package.json#L65, custom generators are tested only inside the create-client module.

J3m5 commented 7 months ago

Hello @misterx,

Thank you for bringing this to our attention. We plan to address this issue in an upcoming release. Please stay tuned for updates!