Skip to content

chore(npm): replace axios with native node:http/node:https - #2350

Closed
rafaeelaudibert wants to merge 7 commits into
axodotdev:mainfrom
PostHog:chore/remove-axios-npm-installer
Closed

rafaeelaudibert wants to merge 7 commits into
axodotdev:mainfrom
PostHog:chore/remove-axios-npm-installer

Conversation

@rafaeelaudibert

@rafaeelaudibert rafaeelaudibert commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

The only reason why @PostHog depends on axios is because of cargo-dist. We don't want that anymore, so... here's a contribution!

Part of the e18e (https://e18e.dev) ecosystem cleanup effort. Remove axios, axios-proxy-builder, console.table, and rimraf from the npm installer template dependencies, replacing them with Node.js built-in modules. This reduces production dependencies from 42 packages to 1 (detect-libc).

See: https://e18e.dev/docs/replacements/fetch.html

  • Replace axios HTTP client with http/https built-in modules
  • Implement redirect following (up to 5 hops) inline
  • Implement HTTP CONNECT proxy tunneling for HTTPS through HTTP proxies, with support for proxy authentication and NO_PROXY
  • Replace rimraf.sync() with custom rmSync function - can use fs.rmSync() once we bump to v14.14+
  • Remove dead console.table import (cTable was never referenced)
  • Regenerate npm-shrinkwrap.json (537 lines → 49 lines)
  • Update test snapshots

Part of the e18e (https://e18e.dev) ecosystem cleanup effort. Remove
axios, axios-proxy-builder, console.table, and rimraf from the npm
installer template dependencies, replacing them with Node.js built-in
modules. This reduces production dependencies from 42 packages to 1
(detect-libc).

See: https://e18e.dev/docs/replacements/fetch.html

- Replace axios HTTP client with node:https/node:http built-in modules
- Implement redirect following (up to 5 hops) inline
- Implement HTTP CONNECT proxy tunneling for HTTPS through HTTP proxies,
  with support for proxy authentication and NO_PROXY
- Replace rimraf.sync() with fs.rmSync() (available since Node 14.14)
- Remove dead console.table import (cTable was never referenced)
- Regenerate npm-shrinkwrap.json (537 lines → 49 lines)
- Update test snapshots
@rafaeelaudibert
rafaeelaudibert force-pushed the chore/remove-axios-npm-installer branch from 2e40960 to a649eab Compare April 2, 2026 03:54
@rafaeelaudibert

Copy link
Copy Markdown
Contributor Author

CC @mistydemeo since you seem to be the most active maintainer here :)

@tnkuehne tnkuehne left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests from #2330 pass on this one! LGTM

@rafaeelaudibert

Copy link
Copy Markdown
Contributor Author

Thanks for the confirmation @tnkuehne! @mistydemeo would love a review here!

@20jasper

20jasper commented Apr 12, 2026 •

Copy link
Copy Markdown
Contributor

Good work! I was just about to open a PR for the same 😄

rimraf was 5MB of transitive deps removed alone (glob was the main offender)

This PR closes #2224

@20jasper

Copy link
Copy Markdown
Contributor

This PR reduces installed size by 56%, 11M -> 4.8M

@rafaeelaudibert

Copy link
Copy Markdown
Contributor Author

Nice, even better! 4.8M is cool 😎

@mistydemeo

Copy link
Copy Markdown
Contributor

Sorry for the delay getting to this; will review soon.

@mistydemeo mistydemeo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again! Got a couple of minor comments, and will get @Gankra to take a look too. I'll also do some testing before we merge anything.

Do you mind bumping the minimum node in the package.json too? From what you're describing looks like the new minimum is 18.

- Bump engines.node to >=18 (the new minimum after dropping axios)
- Preserve axios behavior of allowing password-only proxy auth
- Drop stray space in `constructor (` for prettier consistency

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@rafaeelaudibert
rafaeelaudibert requested a review from mistydemeo May 5, 2026 16:33
rafaeelaudibert and others added 2 commits May 5, 2026 13:37
Reverts the rename to `pkg` introduced when removing axios — the
original name was `package`, which works fine in this CommonJS file.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@rafaeelaudibert

Copy link
Copy Markdown
Contributor Author

@mistydemeo changes have been addressed! I've also merged with master to make diff cleaner

@WarningImHack3r

Copy link
Copy Markdown

@rafaeelaudibert @mistydemeo why does the minimum Node version needs to be bumped after dropping axios? All the Node modules used in the replacement do work with this old version AFAIK, don’t they? (don’t get me wrong, 18 is very reasonable and even too old itself, but dropping support for versions despite no technical limitations seems weird)

@mistydemeo

Copy link
Copy Markdown
Contributor

@WarningImHack3r The fetch API this PR uses was introduced in Node 18.

@WarningImHack3r

Copy link
Copy Markdown

The fetch API this PR uses

I reviewed the code a good half dozen times since it’s been created, and I don’t see any usage of fetch anywhere, as those have (specifically?) been avoided by using node:http and node:https?

Unless some precise APIs introduced recently have been used, this PR looks good with Node 14 support (or even less)

@20jasper

20jasper commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

The fetch API this PR uses

I reviewed the code a good half dozen times since it’s been created, and I don’t see any usage of fetch anywhere, as those have (specifically?) been avoided by using node:http and node:https?

Unless some precise APIs introduced recently have been used, this PR looks good with Node 14 support (or even less)

This PR will require at least v14.18.0 since the node: scheme was backported to node v14.18.0,

v16.0.0, v14.18.0 | Added node: import support to require(...).
https://nodejs.org/api/modules.html#built-in-modules

@WarningImHack3r

Copy link
Copy Markdown

This PR will require at least v14.18.0 since the node: scheme was backported to node v14.18.0,

v16.0.0, v14.18.0 | Added node: import support to require(...).
nodejs.org/api/modules.html#built-in-modules

This is for require(), node: prefix was added to ESM imports in 14.13.1 & 12.20 :D https://nodejs.org/api/esm.html#node-imports

@mistydemeo

Copy link
Copy Markdown
Contributor

I reviewed the code a good half dozen times since it’s been created, and I don’t see any usage of fetch anywhere

Yep, I read the link from the PR description but missed that the API described there wasn't actually the one used in this PR 😅

@rafaeelaudibert

Copy link
Copy Markdown
Contributor Author

@mistydemeo @WarningImHack3r I apologize, that's my fault! I changed approach in the middle of it, but then forgot to actually think about it when implementing the node changes. I'll revert it back to the previous node version, this should make this easier to merge.

I'll be able to get to this next week.

@WarningImHack3r

Copy link
Copy Markdown

Ok, so I just went ahead and did a manual checkup of every addition and their Node support so we're as fair as possible with the actual needs. Here are the results (once again, I don't care about old Node specifically at all, I even think we should drop everything non-supported, but it's one less breaking change for this PR to get approved and it doesn't close doors for no reason for the 3 people still using old Node):

  • rmSync: added in 14.14.0
  • node: prefix in require (that I think we could get rid of if it introduces compatibility issues, it's not mandatory) (sorry @20jasper, I mentioned ESM but I forgot we're still in CJS here, my reply was irrelevant and you were right!): added in 14.18.0

All the rest has been supported since basically forever (< v1)

So, as far as my research goes, we can either support >=14.18 if we keep the PR as is, OR go as low as >=14.14 if we replace node:http(s) in the require calls with http(s)!

rafaeelaudibert and others added 3 commits May 18, 2026 12:37
The node: prefix in require() was added in Node 14.18.0. Drop it so
the npm installer floor stays compatible with older Node 14 patches.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
fs.rmSync was the last API on this template requiring Node >= 14.14.0.
Replace it with a small drop-in polyfill so the npm installer once again
works on the same floor it had before the axios removal (>= 14). The
polyfill is annotated to be removed once the floor is bumped to >= 14.14.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This snapshot still reflected the pre-PR axios-based installer because
the original axios-removal commit couldn't regenerate it locally
(omnibor-cli is required to run this test and wasn't installed). Bring
it in line with the rest of the npm snapshots.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Comment on lines +20 to +45
// Drop-in replacement for fs.rmSync, which was only added in Node 14.14.0.
// Once our minimum supported Node version is >= 14.14.0, this can be removed
// and callers can switch back to fs.rmSync directly.
function rmSync(target, options) {
const { recursive = false, force = false } = options || {};
let stat;
try {
stat = lstatSync(target);
} catch (e) {
if (force && e.code === "ENOENT") return;
throw e;
}
if (stat.isDirectory()) {
if (!recursive) {
const err = new Error(`EISDIR: illegal operation on a directory, ${target}`);
err.code = "EISDIR";
throw err;
}
for (const entry of readdirSync(target)) {
rmSync(join(target, entry), { recursive: true, force });
}
rmdirSync(target);
} else {
unlinkSync(target);
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WarningImHack3r @mistydemeo this is my attempt to keep this at >= 14 since I believe moving to >= 14.14.0 might be a breaking change.

Let me know how you feel around this, I can see this being a problem, in which case we can just bump to >= 14.14.0 instead.

@rafaeelaudibert

Copy link
Copy Markdown
Contributor Author

@WarningImHack3r @mistydemeo I've pushed some changes that mean we can go back to supporting Node >= 14 like before the changes.

Of course, this means we have to ship some inline code that is native to Node in more modern versions, but I feel like this is a reasonable change to keep the backwards compatibility.

I would suggest the maintainers to consider releasing a new breaking version soon bumping to a newer Node version, there's a lot that can be changed in this repo to make it more modern while only supporting supported Node versions.

@WarningImHack3r WarningImHack3r left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

gankra-oai
gankra-oai approved these changes May 18, 2026 •
@Gankra

Gankra commented May 18, 2026

Copy link
Copy Markdown
Contributor

I'm mildly inclined to just bump the node version we require since the one you want is like, from 2020? But since you already did the legwork it seems fine.

Confirmed the proxy variables you checked are used right, and that we're not dropping anything. I can't speak super well to the precise node APIs but if it works, it works.

@WarningImHack3r

Copy link
Copy Markdown

Kudos to the single misformatted file ruining the CI and preventing merging

@mistydemeo

Copy link
Copy Markdown
Contributor

I'll merge a squashed version with the appropriate style changes.

@rafaeelaudibert

Copy link
Copy Markdown
Contributor Author

Closed by #2400 :)

tysm!

jcarver989 pushed a commit to contextbridge/aether that referenced this pull request Nov 2, 2026
AWS Inspector is flagging 32 high and critical CVEs in one of our
images, and they all come from the `npm-shrinkwrap.json` that ships in
`@aether-agent/cli`:

| Package | Version | CVEs |
| --- | --- | --- |
| axios | 1.13.5 | 21 (4 critical) |
| brace-expansion | 5.0.2 | 7 |
| minimatch | 10.2.0 | 3 |
| form-data | 4.0.5 | 1 |

cargo-dist generates that shrinkwrap for its npm installer. npm installs
it exactly as written, so patchwave can't override those versions.
Dependabot doesn't track the cargo-dist version either, which is how
we're still on 0.31.0.

0.32.0 swapped axios and rimraf for Node's built-in `http` and `https`
modules (axodotdev/cargo-dist#2350). I built the
npm package locally with 0.34.0 and `detect-libc` is the only dependency
left in the shrinkwrap.

I went with 0.34.0 over 0.33.1 because it also moves our Apple Silicon
build off `macos-14`, which GitHub is retiring. It only came out today,
though, and we normally wait 7 days on Dependabot bumps. Feedback
welcome.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants