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

Unable to use axios server side with the new strapi plugin command #15

Closed
Alexnortung opened this issue May 1, 2024 · 2 comments
Closed
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: sdk-plugin

Comments

@Alexnortung
Copy link

Bug report

Required System information

  • Node.js version: 18.18.2
  • Yarn version: 4.0.1
  • Strapi version: 4.24.0
  • Database: sqlite
  • Operating system: Linux
  • Is your project Javascript or Typescript: ts

Describe the bug

I wanted to try to use the new strapi plugin command to create a new plugin. I know it is experimental, but I think you want the feedback anyway. It is not possible to use axios on the server side, when axios is called, the process just crashes. This seems to be a problem with the bundler.

Steps to reproduce the behavior

  1. Create a new plugin strapi plugin:init
  2. (Do not install axios as it may conflict with helper-plugin)
  3. Create a route and controller that uses axios to make a request
  4. Send a request to the route using axios.
  5. See that the server crashed

Expected behavior

I expected it would be possible to use axios on the server.

Additional context

This discussion tells that it might be something with the bundler

@Alexnortung
Copy link
Author

I have found a workaround for anyone else having this issue.

import axios from 'axios';
import axiosHttpAdapter from 'axios/lib/adapters/http.js';

const client = axios.create({
  adapter: axiosHttpAdapter,
});

Then use the client in your services

@joshuaellis joshuaellis transferred this issue from strapi/strapi May 14, 2024
@hanpaine hanpaine added issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: sdk-plugin labels Jul 30, 2024
@innerdvations
Copy link
Collaborator

I believe this is not an issue in v5. If there are still problems in v4, we can move this back to the strapi/strapi repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around source: sdk-plugin
Projects
Status: Fixed/Shipped
Development

No branches or pull requests

3 participants