-
-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[ERR_PACKAGE_PATH_NOT_EXPORTED] when trying to import anything from lib/helpers #5072
Comments
Seeing similar with node.js ES6 modules, e.g. import axios from 'axios'
import config from 'axios-debug-log'
... BehaviourAt runtime,
EnvironmentAxios Version [1.1.2] |
@daniil4udo @josephh Does 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 behaviorWas able to import the helper (used to work in 0.27.1) EnvironmentAxios Version [1.1.3] |
@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 |
@msalimbene the origin of the problem is the same. the difference is that you're trying to import all helpers, where I need just 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 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 to #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 ? Thanks |
Any update here? 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 |
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
|
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 import isAbsoluteURL from 'axios/unsafe/helpers/isAbsoluteURL.js'; |
Starting from which version ?
Well, what's a non-risky way to create adapters that the maintainers won't add inside Axios ? |
v1.4.0 (#5677)
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:
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: #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 |
Maybe migrate to xior: import {
isAbsoluteURL,
} from 'xior'; and support utils: import lru from 'tiny-lru';
import {
encodeParams,
merge as deepMerge,
delay as sleep,
buildSortedURL,
isAbsoluteURL,
} from 'xior'; |
No adapters, which is what this issue is about. |
+1 experiencing this issue |
#5189 (comment) - mentioned the issue here, we need it to be fixed somohow as its the last issue in our snyk report so +1 |
Trying to import helper into my project:
Getting:
Expected behavior
Was able to import the helper (used to work in 0.27)
Environment
The text was updated successfully, but these errors were encountered: