require() → import converter

https://observablehq.com/@ambassadors/require-import-converter

If you’re migrating old notebooks to Observable 2.0, you’ve probably hit this: require("some-package@1.2.3") just doesn’t work anymore, and figuring out the right import URL by hand is more annoying than it should be — especially for older packages that never published real ESM, or require() calls that point at a specific file inside a package (require("three@0.104.0/build/three.min.js")).

This notebook is a small tool (built with Observable AI) that does the migration for you: paste in your old require(...) line(s), and it resolves an exact version, actually tries real dynamic imports against jsDelivr/esm.sh/Skypack (falling back to a legacy global-script pattern if nothing else works), and hands back verified, paste-ready import statements — with a one-click copy button. It also handles a few real-world edge cases that came up while I built it: multi-package require("a", "b") merges, subpaths, and malformed/unparseable calls (reported clearly instead of silently vanishing).

1 Like