nextcloud-libraries / nextcloud-axios

Simple, typed wrapper of an Axios instance for Nextcloud https://npmjs.org/@nextcloud/axios
https://nextcloud.github.io/nextcloud-axios/
GNU General Public License v3.0
8 stars 5 forks source link

The 2.4 release breaks cypress in many repos #638

Open skjnldsv opened 10 months ago

skjnldsv commented 10 months ago
          The 2.4 release breaks cypress in many repos for some reason.

https://github.com/nextcloud/viewer/actions/runs/5989883555/job/16246600700 https://github.com/nextcloud/photos/actions/runs/5798646767/job/15717925031

Originally posted by @skjnldsv in https://github.com/nextcloud-libraries/nextcloud-axios/issues/627#issuecomment-1694614122

susnux commented 10 months ago

It provides correct exports, I guess the tests using imports but run as CJS instead of ESM? In this case the using projects probably missing the jest transform for @nextcloud/axios.

(Its a pitty jest still does not support it oom)

skjnldsv commented 10 months ago

In this case the using projects probably missing the jest transform for @nextcloud/axios.

Nope, Viewer doesn't even have jest :see_no_evil:

EDIT: it does have the dependency installed for some reason, and removing it makes it work. But we are not using jest :thinking:

EDIT2: nope, still fails, so the 2.4 release does have something weird in it :thinking:

feefladder commented 8 months ago

Posting here since I think it is related: I had an issue when developing my app. I wanted to have an axios instance that makes external calls to another website, as well as the @nextcloud/axios instance provided by this library. This lead to an error that sometimes showed up and sometimes did not, depending on the order of installation:

So far so not-good, but how to solve this? Well, it turns out @nextcloud/axios is built to include the line const axios = require("axios"), which leads to this issue. Indeed, by going into node_modules/@nextcloud/axios/index.cjs and changing to const axios=require("axios").default solves this issue. image

EDIT: So running make/npm run build twice will result in the error. Then adding .default and running npm run build once will solve it again

feefladder commented 8 months ago

Alternatively,and I'm sure there is a better way: in package.json, remove all references to the cjs file:

"main": "dist/index.es.mjs",
  "types": "dist/index.d.ts",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.es.mjs",
      "default": "./dist/index.es.mjs"
    }
  },