Open skjnldsv opened 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)
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:
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:
import axios from "axios"
and all external-axios related codenpm run watch
(using Vite)npm run dev
/npm run build
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.
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
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"
}
},
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