axios
axios copied to clipboard
[ERR_PACKAGE_PATH_NOT_EXPORTED] when trying to import isAbsoluteURL
Trying to import helper into my project:
import isAbsoluteURL from 'axios/lib/helpers/isAbsoluteURL'
Getting:
Module not found: Error: Package path ./lib/helpers/isAbsoluteURL is not exported from package /Users/.../node_modules/axios (see exports field in /Users/.../node_modules/axios/package.json)
Expected behavior
Was able to import the helper (used to work in 0.27)
Environment
- Axios Version [1.1.2]
- Node.js Version [16]
Seeing similar with node.js ES6 modules, e.g.
import axios from 'axios'
import config from 'axios-debug-log'
...
Behaviour
At runtime,
...
"trace":["Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/helpers/isAbsoluteURL' is not defined by \"exports\" in /var/task/node_modules/axios/package.json"," at new NodeError (node:internal/errors:387:5)"," at throwExportsNotFound (node:internal/modules/esm/resolve:464:9)"," at packageExportsResolve (node:internal/modules/esm/resolve:748:3)"," at resolveExports (node:internal/modules/cjs/loader:493:36)"," at Function.Module._findPath (node:internal/modules/cjs/loader:533:31)"," at Function.Module._resolveFilename (node:internal/modules/cjs/loader:942:27)"," at Function.Module._load (node:internal/modules/cjs/loader:804:27)"," at Module.require (node:internal/modules/cjs/loader:1028:19)"," at require (node:internal/modules/cjs/helpers:102:18)"," at Object.<anonymous> (/var/task/node_modules/axios-debug-log/index.js:4:21)"]}
...
Environment
Axios Version [1.1.2] Node.js Version [16]
@daniil4udo @josephh Does 1.1.3 work for you? I still get the same error with 1.1.3 as with 1.0.0 and 1.1.2.
Trying to import helper into my project:
import isAbsoluteURL from 'axios/lib/helpers/isAbsoluteURL'
Getting:
Module not found: Error: Package path ./lib/helpers/isAbsoluteURL is not exported from package /Users/.../node_modules/axios (see exports field in /Users/.../node_modules/axios/package.json)
Expected behavior
Was able to import the helper (used to work in 0.27.1)
Environment
Axios Version [1.1.3] Node.js Version [18.8]
@bt95 no, lib folder (or at least helpers) has to be added to the exports in the package.json. I believe I saw PR #5136 for this issue, hopefully will be merged and released soon
@daniil4udo Perfect! Thanks for info!
@daniil4udo experiencing the same problem with version 1.1.3. Used to work in 0.27.1. Have you been able to solve this?
On a second look isn't exactly the same err, should I open a new ticket:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/defaults' is not defined by "exports" in /Users/salimbene/dev/hlp-bc-contracts-api/node_modules/axios/package.json
[0] at new NodeError (node:internal/errors:372:5)
[0] at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
[0] at packageExportsResolve (node:internal/modules/esm/resolve:753:3)
[0] at resolveExports (node:internal/modules/cjs/loader:482:36)
[0] at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
[0] at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
[0] at Function.Module._load (node:internal/modules/cjs/loader:778:27)
[0] at Module.require (node:internal/modules/cjs/loader:1005:19)
[0] at require (node:internal/modules/cjs/helpers:102:18)
[0] at Object.
@msalimbene the origin of the problem is the same. the difference is that you're trying to import all helpers, where I need just isAbsoluteUrl.
If all helpers will be added to the exports in the package.json, it solves both our problems
Hello,
I'm experiencing the same issue as I wrote an Axios adapter for Tauri inspired by Axios' official adapters, involving several imports under the lib directory, working on v0.x but not v1.x :
import buildURL from 'axios/lib/helpers/buildURL';
import buildFullPath from 'axios/lib/core/buildFullPath';
import {
isFormData,
isArrayBuffer,
isString,
isBlob
} from 'axios/lib/utils';
import AxiosError from 'axios/lib/core/AxiosError';
import { transitional } from 'axios/lib/defaults';
import settle from 'axios/lib/core/settle';
Thanks
Related issues:
- #5189
- #5183
Related to https://github.com/axios/axios/issues/5262
I will look at what we can export but I must warn everyone we would break anything not currently exported without any warning
So there will be no documentation nor support ever regarding community adapters ?
If not, then how can we learn to make good stuff ? (Cf. #5204)
Thanks
Any update here? I've upgraded to the latest, and we're seeing the same thing breaking all our builds.
From reading this thread, sounds like there are many issues in the same area. Any fix or work around in site?
I have the same problem...
Same issue. Any update?
same issue here
I ran into the same issue. We were using the helper libraries to build a full URL. I noticed that the axios-debug-log library encountered a similar issue nearly identical to ours, and this was the fix they implemented: https://github.com/Gerhut/axios-debug-log/commit/df0f23a8c2258c4764227ea93dcd7951a651d90a#diff-e727e4bdf3657fd1d798edcd6b099d6e092f8573cba266154583a746bba0f346R10. Hopefully this is helpful to someone else!
Just want to add my two cents to this. After struggling to find the reason for this error within my own code, I finally noticed that one of my other dependencies was using an old version of axios-cookiejar-support that was throwing this error. Updating that package fixed it for me.
I updated the axios-cookiejar-support package but it didn't help me
Just want to add my two cents to this. After struggling to find the reason for this error within my own code, I finally noticed that one of my other dependencies was using an old version of axios-cookiejar-support that was throwing this error. Updating that package fixed it for me.
maybe the solution is to install a previous version of the package you currently use
Any updates on this issue?
WTAF
Try this, it work for me
// @ts-ignore
import isAbsoluteURL from 'axios/lib/helpers/isAbsoluteURL.js'
The lib folder is exported as unsafe to highlight this is at your risk, since you will import private modules where the semver stability of the interfaces is not guaranteed.
import isAbsoluteURL from 'axios/unsafe/helpers/isAbsoluteURL.js';
The
libfolder is exported asunsafe
Starting from which version ?
this is at your risk
Well, what's a non-risky way to create adapters that the maintainers won't add inside Axios ?
Starting from which version ?
v1.4.0 (#5677)
Well, what's a non-risky way to create adapters that the maintainers won't add inside Axios ?
There are no good enough solutions for now. This is one of the reasons why we need to thoroughly rework the core before adding any new major things because the larger the code base, the more we will have to rewrite and refactor later. In the new codebase, these helpers will be static methods of the AxiosURL (extends URL) class, which are supposed to be public export.
import {forEach, toCamelCase, merge} from "#utils";
import {paramsToString, deserializeParams} from "#helpers";
import platform from '#platform';
import {URLEncodedFormSerializer} from "./Serializers.js";
const defaultOriginURL = new URL(platform.origin);
const defaultOrigin = defaultOriginURL.toString();
class AxiosURL extends URL{
constructor(url, base) {
super(url, base || defaultOrigin);
}
/**
* Determines whether the specified URL is absolute
*
* @param {string} url The URL to test
*
* @returns {boolean} True if the specified URL is absolute, otherwise false
*/
static isAbsoluteURL(url) {
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
// by any combination of letters, digits, plus, period, or hyphen.
// scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
// https://datatracker.ietf.org/doc/html/rfc3986#section-4.3
return /^(([a-z][-a-z\d+.]*:\/?\/?)|(\/\/))/i.test(url);
}
isSameOriginURL(origin) {
origin = origin ? new URL(origin) : defaultOriginURL;
return (
this.protocol === origin.protocol &&
this.host === origin.host &&
(platform.isMSIE || this.port === origin.port)
);
}
/**
* Build a URL by appending params to the end
*
* @param {string} url The base of the url (e.g., http://www.google.com)
* @param {?object} [params] The params to be appended
* @param {?object} [options]
*
* @returns {AxiosURL} The formatted url
*/
static buildURL(url, params, options) {
const urlObj = new this(url);
const {search} = urlObj;
const pairs = [];
const existedParams = search && deserializeParams(search);
if (existedParams) {
params = merge.call({mergeArrays: true}, existedParams, params);
}
console.log(existedParams);
console.log(params);
params && new URLEncodedFormSerializer(options).serialize(params, {
append(key, value) {
pairs.push([key, value]);
}
});
params && (urlObj.search = paramsToString(pairs, options && options.encoder || null));
return urlObj;
}
/**
* Creates a new URL by combining the specified URLs
*
* @param {string} baseURL The base URL
* @param {string} relativeURL The relative URL
*
* @returns {AxiosURL} The combined URL
*/
static combineURLs(baseURL, relativeURL) {
return new this(
String(relativeURL).replace(/^\/+/, ''),
baseURL ? String(baseURL).replace(/\/?\/$/, '') + '/' : undefined
);
}
}
const {prototype} = AxiosURL;
/*defineConstants(prototype, {
ORIGIN: platform.origin
});*/
forEach('href origin protocol username password host hostname port pathname search hash', (key) => {
key !== 'constructor' && Object.defineProperty(prototype, toCamelCase('set ' + key), {
value(newValue) {
this[key] = newValue;
return this;
},
configurable: true
})
});
export default AxiosURL;
I'm on version 1.6.4 and the import literally not working regardless of the unsafe path:
- import isAbsoluteURL from 'axios/lib/helpers/isAbsoluteURL'
- import isAbsoluteURL from 'axios/lib/helpers/isAbsoluteURL.js'
- import isAbsoluteURL from 'axios/unsafe/helpers/isAbsoluteURL'
- import isAbsoluteURL from 'axios/unsafe/helpers/isAbsoluteURL.js'
non of those not working after upgrade axios from 0.25.0 to 1.6.0++
It's worked @Mifrill
Demo code (js version): https://codesandbox.io/p/sandbox/new-wildflower-m3znw4?file=%2Fsrc%2FApp.js%3A10%2C11
TS version: https://codesandbox.io/p/sandbox/lucid-cloud-forked-4fhnzx?file=%2Fsrc%2FApp.tsx%3A12%2C5
Hey @suhaotian thanks for update. It seems like my issue is about Jest config, it's described here: https://github.com/axios/axios/issues/5026. Although I'm not using react, the issue is persists and suggestions with moduleNameMapper or transformIgnorePatterns does not solves that unfortunately.
In browser though, while the following works :
await import('https://esm.sh/axios/unsafe/helpers/isAbsoluteURL.js')
This one doesn't :
await import('https://esm.sh/axios/unsafe/helpers/buildURL.js')
Except when using v0.x :
await import('https://esm.sh/[email protected]/lib/helpers/buildURL.js')
Thanks