bun install error [ERR_REQUIRE_ESM]: Must use import to load ES Module
bun install throws an error:
bun install v1.2.2 (c1708ea6)
🚚 pnpm... internal/modules/cjs/loader.js:1025
throw new ERR_REQUIRE_ESM(filename);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/rsholmes/Downloads/amazon-kindle-bulk-downloader-main/node_modules/puppeteer/install.mjs
at Object.Module._extensions..mjs (internal/modules/cjs/loader.js:1025:9)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'ERR_REQUIRE_ESM'
}
error: postinstall script from "puppeteer" exited with 1
Using Linux Mint 21.3.
I just tried bun install https://github.com/treetrum/amazon-kindle-bulk-downloader
It looks like it worked?
Got it working...a bit of hacking needed. This is on my Mac....
- bun install https://github.com/treetrum/amazon-kindle-bulk-downloader
- I changed the directory to the path of the project on my mac (/Users/sean/node_modules/amazon-kindle-bulk-downloader)
- I hard coded my username and pwd in the credentials.ts file bec. I didn't have time to figure out the env config setup. I gotta get to work!
- I ran --> bun run start --baseUrl "https://www.amazon.com"
- I selected the oldest kindle on my account and bam...it found over 500 books and downloaded them into a subdirectory called 'Downloads"
I'm not sure why my other kindles said 0 books found but it worked so thanks to the author.
I just tried bun install https://github.com/treetrum/amazon-kindle-bulk-downloader
It looks like it worked?
That gives exactly the same error:
$ bun install https://github.com/treetrum/amazon-kindle-bulk-downloader
bun add v1.2.2 (c1708ea6)
⚙️ puppeteer [1/1] internal/modules/cjs/loader.js:1025
throw new ERR_REQUIRE_ESM(filename);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/rsholmes/Downloads/akbd/node_modules/puppeteer/install.mjs
at Object.Module._extensions..mjs (internal/modules/cjs/loader.js:1025:9)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'ERR_REQUIRE_ESM'
}
error: postinstall script from "puppeteer" exited with 1
System info:
System:
Kernel: 5.15.0-131-generic x86_64 bits: 64 compiler: gcc v: 11.4.0 Desktop: Cinnamon 6.0.4
tk: GTK 3.24.33 wm: muffin vt: 7 dm: LightDM 1.30.0 Distro: Linux Mint 21.3 Virginia
base: Ubuntu 22.04 jammy
Machine:
Type: Desktop System: System76 product: Wild Dog Pro v: wilp14 serial: <superuser required>
Chassis: type: 3 v: wilp14 serial: <superuser required>
Mobo: Gigabyte model: Z370 HD3P-CF v: x.x serial: <superuser required>
UEFI: American Megatrends v: F5 Z5 date: 12/15/2017
CPU:
Info: 6-core model: Intel Core i5-8400 bits: 64 type: MCP smt: <unsupported> arch: Coffee Lake
rev: A cache: L1: 384 KiB L2: 1.5 MiB L3: 9 MiB
Speed (MHz): avg: 904 high: 1428 min/max: 800/4000 cores: 1: 800 2: 800 3: 800 4: 800 5: 800
6: 1428 bogomips: 33599
Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
Graphics:
Device-1: Intel CoffeeLake-S GT2 [UHD Graphics 630] vendor: Gigabyte CometLake-S driver: i915
v: kernel ports: active: HDMI-A-1 empty: DP-1,HDMI-A-2,HDMI-A-3 bus-ID: 00:02.0
chip-ID: 8086:3e92 class-ID: 0300
Device-2: Logitech HD Pro Webcam C920 type: USB driver: snd-usb-audio,uvcvideo
bus-ID: 1-8.4:10 chip-ID: 046d:082d class-ID: 0102 serial: <filter>
Display: x11 server: X.Org v: 1.21.1.4 driver: X: loaded: modesetting unloaded: fbdev,vesa
gpu: i915 display-ID: :0 screens: 1
Screen-1: 0 s-res: 1920x1080 s-dpi: 96 s-size: 508x285mm (20.0x11.2") s-diag: 582mm (22.9")
Monitor-1: HDMI-1 mapped: HDMI-A-1 model: Dell S2715H serial: <filter> res: 1920x1080 hz: 60
dpi: 82 size: 598x336mm (23.5x13.2") diag: 686mm (27") modes: max: 1920x1080 min: 720x400
OpenGL: renderer: Mesa Intel UHD Graphics 630 (CFL GT2) v: 4.6 Mesa 23.2.1-1ubuntu3.1~22.04.3
direct render: Yes
Audio:
Device-1: Intel 200 Series PCH HD Audio vendor: Gigabyte driver: snd_hda_intel v: kernel
bus-ID: 00:1f.3 chip-ID: 8086:a2f0 class-ID: 0403
Device-2: Logitech HD Pro Webcam C920 type: USB driver: snd-usb-audio,uvcvideo
bus-ID: 1-8.4:10 chip-ID: 046d:082d class-ID: 0102 serial: <filter>
Sound Server-1: ALSA v: k5.15.0-131-generic running: yes
Sound Server-2: JACK v: 1.9.20 running: no
Sound Server-3: PulseAudio v: 15.99.1 running: yes
Sound Server-4: PipeWire v: 0.3.48 running: yes
Network:
Device-1: Intel Ethernet I219-V vendor: Gigabyte driver: e1000e v: kernel port: N/A
bus-ID: 00:1f.6 chip-ID: 8086:15b8 class-ID: 0200
IF: enp0s31f6 state: down mac: <filter>
Device-2: Intel Wireless 8260 driver: N/A pcie: speed: 2.5 GT/s lanes: 1 bus-ID: 08:00.0
chip-ID: 8086:24f3 class-ID: 0280
Device-3: Ralink RT5572 Wireless Adapter type: USB driver: rt2800usb bus-ID: 1-11:5
chip-ID: 148f:5572 class-ID: 0000 serial: <filter>
IF: wlx9cefd5fdd05e state: up mac: <filter>
IF-ID-1: virbr0 state: down mac: <filter>
Bluetooth:
Device-1: Intel Bluetooth wireless interface type: USB driver: btusb v: 0.8 bus-ID: 1-14:9
chip-ID: 8087:0a2b class-ID: e001
Report: hciconfig ID: hci0 rfk-id: 0 state: up address: <filter> bt-v: 2.1 lmp-v: 4.2
sub-v: 100 hci-v: 4.2 rev: 100
Drives:
Local Storage: total: 2.27 TiB used: 1.56 TiB (68.7%)
ID-1: /dev/sda vendor: Samsung model: SSD 850 EVO M.2 500GB size: 465.76 GiB speed: 6.0 Gb/s
type: SSD serial: <filter> rev: 1B6Q scheme: GPT
ID-2: /dev/sdb type: USB vendor: Western Digital model: WD My Passport 25E2 size: 1.82 TiB
type: N/A serial: <filter> rev: 4005 scheme: MBR
Partition:
ID-1: / size: 456.89 GiB used: 288.86 GiB (63.2%) fs: ext4 dev: /dev/sda2
ID-2: /boot/efi size: 511 MiB used: 6.1 MiB (1.2%) fs: vfat dev: /dev/sda1
Swap:
ID-1: swap-1 type: file size: 12 GiB used: 4.63 GiB (38.5%) priority: -2 file: /swapfile
USB:
Hub-1: 1-0:1 info: Hi-speed hub with single TT ports: 16 rev: 2.0 speed: 480 Mb/s
chip-ID: 1d6b:0002 class-ID: 0900
Hub-2: 1-8:2 info: VIA Labs VL813 Hub ports: 4 rev: 2.1 speed: 480 Mb/s chip-ID: 2109:2813
class-ID: 0900
Device-1: 1-8.2:4 info: Logitech Keyboard K120 type: Keyboard,HID driver: hid-generic,usbhid
interfaces: 2 rev: 1.1 speed: 1.5 Mb/s power: 90mA chip-ID: 046d:c31c class-ID: 0300
Device-2: 1-8.4:10 info: Logitech HD Pro Webcam C920 type: Video,Audio
driver: snd-usb-audio,uvcvideo interfaces: 4 rev: 2.0 speed: 480 Mb/s power: 500mA
chip-ID: 046d:082d class-ID: 0102 serial: <filter>
Hub-3: 1-9:3 info: Terminus FE 2.1 7-port Hub ports: 7 rev: 2.0 speed: 480 Mb/s power: 100mA
chip-ID: 1a40:0201 class-ID: 0900
Device-1: 1-9.5:6 info: Razer USA Pro Click type: Mouse,Keyboard driver: hid-generic,usbhid
interfaces: 3 rev: 2.0 speed: 12 Mb/s power: 500mA chip-ID: 1532:0077 class-ID: 0300
Device-2: 1-11:5 info: Ralink RT5572 Wireless Adapter type: Network driver: rt2800usb
interfaces: 1 rev: 2.0 speed: 480 Mb/s power: 450mA chip-ID: 148f:5572 class-ID: 0000
serial: <filter>
Device-3: 1-12:8 info: Alcor Micro Flash Card Reader/Writer type: Mass Storage
driver: usb-storage interfaces: 1 rev: 2.0 speed: 480 Mb/s power: 250mA chip-ID: 058f:6362
class-ID: 0806 serial: <filter>
Device-4: 1-14:9 info: Intel Bluetooth wireless interface type: Bluetooth driver: btusb
interfaces: 2 rev: 2.0 speed: 12 Mb/s power: 100mA chip-ID: 8087:0a2b class-ID: e001
Hub-4: 2-0:1 info: Super-speed hub ports: 10 rev: 3.0 speed: 5 Gb/s chip-ID: 1d6b:0003
class-ID: 0900
Device-1: 2-3:2 info: Western Digital My Passport (WD40NMZW) type: Mass Storage
driver: usb-storage interfaces: 1 rev: 3.1 speed: 5 Gb/s power: 896mA chip-ID: 1058:25e2
class-ID: 0806 serial: <filter>
Hub-5: 2-8:3 info: VIA Labs VL813 Hub ports: 4 rev: 3.0 speed: 5 Gb/s chip-ID: 2109:0813
class-ID: 0900
Hub-6: 3-0:1 info: Hi-speed hub with single TT ports: 2 rev: 2.0 speed: 480 Mb/s
chip-ID: 1d6b:0002 class-ID: 0900
Hub-7: 4-0:1 info: Super-speed hub ports: 2 rev: 3.1 speed: 10 Gb/s chip-ID: 1d6b:0003
class-ID: 0900
Hub-8: 5-0:1 info: Hi-speed hub with single TT ports: 4 rev: 2.0 speed: 480 Mb/s
chip-ID: 1d6b:0002 class-ID: 0900
Hub-9: 6-0:1 info: Super-speed hub ports: 4 rev: 3.0 speed: 5 Gb/s chip-ID: 1d6b:0003
class-ID: 0900
Sensors:
System Temperatures: cpu: 27.8 C mobo: 16.8 C
Fan Speeds (RPM): N/A
Repos:
Packages: 4022 apt: 3926 nix-default: 48 flatpak: 40 snap: 8
No active apt repos in: /etc/apt/sources.list
Active apt repos in: /etc/apt/sources.list.d/antiprism-ppa-jammy.list
1: deb http: //ppa.launchpad.net/antiprism/ppa/ubuntu jammy main
No active apt repos in: /etc/apt/sources.list.d/appimagelauncher-team-stable-jammy.list
No active apt repos in: /etc/apt/sources.list.d/bit-team-stable-jammy.list
No active apt repos in: /etc/apt/sources.list.d/celestia-bintray.list
No active apt repos in: /etc/apt/sources.list.d/gencfsm-ppa-jammy.list
Active apt repos in: /etc/apt/sources.list.d/gierens.list
1: deb http: //deb.gierens.de stable main
Active apt repos in: /etc/apt/sources.list.d/git-core-ppa-jammy.list
1: deb http: //ppa.launchpad.net/git-core/ppa/ubuntu jammy main
Active apt repos in: /etc/apt/sources.list.d/inkscape_dev-stable-jammy.list
1: deb [signed-by=/etc/apt/keyrings/inkscape_dev-stable-jammy.gpg] https: //ppa.launchpadcontent.net/inkscape.dev/stable/ubuntu jammy main
Active apt repos in: /etc/apt/sources.list.d/josm.list
1: deb [signed-by=/usr/local/share/keyrings/josm-apt.gpg] https: //josm.openstreetmap.de/apt jammy universe
Active apt repos in: /etc/apt/sources.list.d/kdenlive-kdenlive-stable-jammy.list
1: deb http: //ppa.launchpad.net/kdenlive/kdenlive-stable/ubuntu jammy main
Active apt repos in: /etc/apt/sources.list.d/kicad-kicad-8_0-releases-jammy.list
1: deb [signed-by=/etc/apt/keyrings/kicad-kicad-8_0-releases-jammy.gpg] https: //ppa.launchpadcontent.net/kicad/kicad-8.0-releases/ubuntu jammy main
Active apt repos in: /etc/apt/sources.list.d/kicad-kicad-dev-nightly-jammy.list
1: deb http: //ppa.launchpad.net/kicad/kicad-dev-nightly/ubuntu jammy main
Active apt repos in: /etc/apt/sources.list.d/libreoffice-ppa-jammy.list
1: deb [arch=amd64 signed-by=/etc/apt/keyrings/libreoffice-ppa-jammy.gpg] https: //ppa.launchpadcontent.net/libreoffice/ppa/ubuntu jammy main
No active apt repos in: /etc/apt/sources.list.d/mozilla.list
Active apt repos in: /etc/apt/sources.list.d/official-package-repositories.list
1: deb http: //packages.linuxmint.com virginia main upstream import backport
2: deb http: //archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
3: deb http: //archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
4: deb http: //archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
5: deb http: //security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
Active apt repos in: /etc/apt/sources.list.d/protonvpn-stable.list
1: deb [signed-by=/usr/share/keyrings/protonvpn-stable-archive-keyring.gpg] https: //repo.protonvpn.com/debian stable main
Active apt repos in: /etc/apt/sources.list.d/sane-project-sane-git-jammy.list
1: deb [signed-by=/etc/apt/keyrings/sane-project-sane-git-jammy.gpg] https: //ppa.launchpadcontent.net/sane-project/sane-git/ubuntu jammy main
Active apt repos in: /etc/apt/sources.list.d/slgobinath-gcalendar-jammy.list
1: deb http: //ppa.launchpad.net/slgobinath/gcalendar/ubuntu jammy main
No nix channels found for user: rsholmes
Info:
Processes: 374 Uptime: 2d 44m wakeups: 0 Memory: 23.34 GiB used: 14.18 GiB (60.7%) Init: systemd
v: 249 runlevel: 5 Compilers: gcc: 11.4.0 alt: 11/12/9 Client: Cinnamon v: 6.0.4 inxi: 3.3.13
I just tried bun install https://github.com/treetrum/amazon-kindle-bulk-downloader
It looks like it worked?
That gives me the error mentioned here. In addition, when I try that command in Arch Linux or in a fresh copy of Linux Mint 22.1 on a USB stick, I don't get that error but I get another one. But downloading the repo zip, extracting it, and doing bun install in that directory does work in Arch.
So no, I don't think that command is what should be used.
@rsholmes what I’m seeing in your report is actually not on install but on the post install puppeteer script.
It should be bun install inside the project directory, not the command with the repo url appended, AFAIK. If you are still getting the original error, I would suggest ensuring puppeteer and its chrome engine are installed correctly for your system.
Yes, I'm doing bun install in the project directory.
I don't know anything about puppeteer, but I assume it is something included as part of this package; in the node_modules directory are subdirectories @puppeteer, puppeteer, and puppeteer_core. If these are incorrectly configured then that presumably is an installation fault. But I have no idea how to check whether they are correct. Is it possible there is some other, incompatible, version of puppeteer installed elsewhere taking precedence? But that seems unlikely since the error message specifically calls out /home/rsholmes/Downloads/amazon-kindle-bulk-downloader-main/node_modules/puppeteer/install.mjs.
Exact same problem for me, on *buntu 24.04.
I find it interesting that subsequent bun install runs report zero errors, I'm cynically guessing because like every language-specific package manager bun is functionally incomplete, the specific deficiency in this case being it doesn't have any persistent awareness that the postinstall step failed and so considers everything installed fine. But the subsequent command for installing a special version of Chrome to be used by the tool then fails like this:
keithzg@district:~/Code/git/amazon-kindle-bulk-downloader$ bun puppeteer browsers install firefox
/home/keithzg/Code/git/amazon-kindle-bulk-downloader/node_modules/puppeteer/lib/cjs/puppeteer/node/cli.js:26
buildId: puppeteer_js_1.default.configuration.chrome?.version ||
^
SyntaxError: Unexpected token .
at Module._compile (internal/modules/cjs/loader.js:718:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
at internal/main/run_main_module.js:17:11
error: "puppeteer" exited with code 1
Even if I entirely wipe out the git checkout and run bun puppeteer browsers install firefox, the same error occurs. I'm guessing it's part of the postinstall, but I could be wrong, I'm not even entirely sure I've used bun ever before.
@keithzg I'm not entirely sure why you're attempting to install firefox? This tool is only designed/tested with puppeteer's chrome implementation.
The correct command for installing the required browser is:
bunx puppeteer browsers install chrome
@rsholmes wondering if you're still having issues with this? I've slimmed down the dependencies a little bit on this app in the hopes that install steps are less error prone.
Are you able to pull the repo and try again?
I've had very good luck on clean OS installs in my testing.
I had success using my laptop running Arch so didn't go back to the Mint case, and yesterday I installed Mint 22.1 (with which I'd previously had success, using a USB stick install). So I'm not in a position to test for whether it got fixed or not.
@keithzg I'm not entirely sure why you're attempting to install firefox? This tool is only designed/tested with puppeteer's chrome implementation.
The correct command for installing the required browser is:
bunx puppeteer browsers install chrome
Yeah I mistakenly copy-pasted the wrong instance of me trying and it printing the same error, I originally was indeed more reasonably trying bun puppeteer browsers install chrome (I installed via https://bun.sh/docs/installation#downloading-bun-binaries-directly and there was just a single binary executable provided, bun; in my testing I got the exact same errors whether I wrote bun x puppeteer etcetc or just bun puppeteer etcetc). In fact, the same error is printed with just bun puppeteer, which I eventually got to after trying other browsers as arguments too, all just to try and elicit any difference in response.
@rsholmes wondering if you're still having issues with this? I've slimmed down the dependencies a little bit on this app in the hopes that install steps are less error prone.
Are you able to pull the repo and try again?
I've had very good luck on clean OS installs in my testing.
On my admittedly rather unclean *buntu 24.04 system, pulling a fresh copy still results in the .../cjs/loader.js error the same as ever, other than I see it's a different line number cited than the original post here heh:
keithzg@district:~/Code/git/amazon-kindle-bulk-downloader$ bun install
bun install v1.2.3 (8c4d3ff8)
🚚 @eslint-community/eslint-utils... internal/modules/cjs/loader.js:819
throw new ERR_REQUIRE_ESM(filename);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/keithzg/Code/git/amazon-kindle-bulk-downloader/node_modules/puppeteer/install.mjs
at Object.Module._extensions..mjs (internal/modules/cjs/loader.js:819:9)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
at internal/main/run_main_module.js:17:11
error: postinstall script from "puppeteer" exited with 1
keithzg@district:~/Code/git/amazon-kindle-bulk-downloader$ git log | head
commit d71d350afdf0917aa27974e3c4e97d33148a8fe0
Author: Sam Davis <[email protected]>
Date: Tue Feb 25 13:56:10 2025 +1100
Update
Other users have had some luck with these kinds of puppeteer errors by upgrading their environments. I'd look at upgrading:
- your package manager
- node
- npm
And seeing if that helps?
Is bun not my package manager? I downloaded the absolute latest stable version of it directly from the project website, so I would assume there are no reasonable upgrades to make there?
Ah, I see, bun is a JavaScript runtime, npm is the package manager, and nodejs is . . . also a JavaScript runtime? Okay I'm still confused but I'm gonna move on. Here's my versions and their sources:
keithzg@district:~$ which bun && bun --version
/home/keithzg/bin/bun
1.2.3
keithzg@district:~$ which nodejs && nodejs --version
/usr/bin/nodejs
v18.19.1
keithzg@district:~$ which npm && npm --version
/home/keithzg/.nvm/versions/node/v12.4.0/bin/npm
6.9.0
keithzg@district:~$ which node && node --version
/home/keithzg/.nvm/versions/node/v12.4.0/bin/node
v12.4.0
So I have nodejs in my path which is pointing to the apt package here in the latest Ubuntu LTS, but also a much older node installed via the Node Version Manager from clearly some monkeying around trying to compile some other NodeJS project, and with it a similarly old npm version. That sure sounds like a likely culprit! I should probably just wipe all that and try to go back to stable and automatically-upgraded distro packages but I'll try first using that setup to use the latest stable NodeJS stack. Choosing what to install based on the output of nvm ls-remote --lts, which seems to align with a quick check of https://nodejs.org/, I end up with
v22.14.0 (npm v10.9.2)
And yup, you guessed it, bun puppeteer browsers install chrome worked fine after that. In fact, fully uninstalling my local nvm and reverting to purely distro apt packages (other than for bun, which does not appear to have one), aka node version v18.19.1 and npm version 9.2.0, also worked.
I'm using Kubuntu 24.04, and I see that Linux Mint 21.3 is based on Ubuntu 22.04. The versions in the 22.04 repo are node at 12.22.9 and npm at 8.5.1. I wasn't easily able to replicate that because installing that version via NVM got me npm v6.14.15 by default, and upgrading it to the latest supported for that got me to npm v10.2.3, but in fact puppeteer commands failed with the same unexpected token error as above.
I worked back through NodeJS versions using NVM and I can (to the degree that my own questionable setup and poor understanding of the NodeJS ecosystem can be relied upon) confirm that the cutoff appears to be NodeJS v16, because both v16.20.2 (the latest LTS release of v16) and v16.13.0 (the oldest listed LTS of v16) work (even with old npm 8.1.0), but v14.21.3 (the latest LTS release of v14) does not work.
Took a brief look and Debian stable ("Bookworm") is at NodeJS 18.19.0, with oldstable ("Bullseye") at 12.22.12.
Or to sum it all up:
- It looks like this project requires at least NodeJS version 16
- It makes sense then that @rsholmes couldn't run it out of the box on Linux Mint's oldstable, and that should then be expected by any Ubuntu or Debian users still using the previous stable versions of their distro rather than the latest stable,
- but anyone running Debian 12, Ubuntu 24.04, or Linux Mint 22.x (or higher) should be fine
@keithzg thank you SO much for this thorough investigation and report. @treetrum if we have any more Linux users having similar issues, we should point them here, as well as have the node v16.x minimum requirement at the ready.
@keithzg nice job hunting this down.
You're absolutely right — both Bun and Node are JS Runtimes, and theoretically are completely standalone.
I tested this tool on an OS without Node/NPM installed at all and was able to run it with no problems. But clearly if you've got Node installed on your system, it can cause issues if its too out of date. Not really sure what would be causing it, but great find nonetheless. My main machine I was doing testing on is setup with Node 20 by default, which would explain why I didn't run into these issues.
Have included a note about this to the README.