Skip to content
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

Imports broken #20306

Closed
Eggwise opened this issue May 13, 2024 · 3 comments
Closed

Imports broken #20306

Eggwise opened this issue May 13, 2024 · 3 comments

Comments

@Eggwise
Copy link
Contributor

Eggwise commented May 13, 2024

Error

We use several components from the strapi code like:

  • transformResponse (from /core-api/controllers/transform)
  • getPaginationInfo (from /core-api/service/pagination)
  • convertPagedToStartLimit (from /core-api/service/pagination)
  • transformPaginationResponse (from /core-api/service/pagination)

Throughout our codebases

Now i think since strapi 4 has been rewritten in Typescript, when we try to upgrade to strapi 4.15.5 it cannot load the functions anymore because they have been moved to the "dist" folder. Though when we try to rename the imports to @strapi/strapi/dist/core-api/service/pagination instead of @strapi/strapi/lib/core-api/service/pagination we get the following error

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/core-api/service/pagination' is not defined by "exports" in

Question

  • What is the reason strapi removed support for internal functions like these? I find it weird because you need these sometimes, especially when you are creating custom endpoints.
  • Is there a way we can fix it or work around it ? I want to prevent copy pasting the strapi code we need and mainting it ourself since it's part of the framework.

System info

  • Node.js version: 18
  • NPM version:
  • Strapi version: 4.15
  • Database: doesnt matter
  • Operating system: Macbook M2
  • Is your project Javascript or Typescript: Javascript
@Eggwise
Copy link
Contributor Author

Eggwise commented May 14, 2024

This also breaks https://github.com/strapi-community/strapi-plugin-slugify
(Error: Could not load js config file /Users/.....//strapi-plugin-slugify/strapi-server.js: Cannot find module '@strapi/strapi/lib/core-api/controller/transform')

and i guess more repo's.

@joshuaellis
Copy link
Member

This isn't a bug, we never supported importing code this way and doing so was at author's own risk. IMO I would copy the code you require into your codebase where possible & notify library authors elsewhere :)

@joshuaellis joshuaellis closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
@Eggwise
Copy link
Contributor Author

Eggwise commented May 14, 2024

This isn't a bug, we never supported importing code this way and doing so was at author's own risk. IMO I would copy the code you require into your codebase where possible & notify library authors elsewhere :)

@joshuaellis

Hi 👋
Thanks for taking the time to look into it and for responding.
We appreciate it.

Are you very sure about your decision though?
Without exposing these methods it's impossible to create custom endpoints that support core strapi behaviour like pagination, and the response format and it's my understanding that strapi is aiming to be highly extensible and at least support more than CRUD only.

Importing and exporting these crucial functions should be straightforward for the strapi team to implement and would help a lot of developers.

Let me know what your thoughts are.

Kind regards,
John

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants