strapi / sdk-plugin

CLI toolkit for developing a Strapi plugin
Other
4 stars 4 forks source link

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

Closed Alexnortung closed 20 hours ago

Alexnortung commented 4 months ago

Bug report

Required System information

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 commented 4 months ago

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

innerdvations commented 20 hours ago

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.