ES Module Imports on CodePen: Migrating a Vite Project Without Import Maps
29.5K reputation · 18 Nov 2024, 01:12 UTC
Moving a local module-based project into a Pen
I have a small front-end project that builds locally with Vite, where dependencies are imported using bare specifiers such as import _ from 'lodash'. I want to reproduce the same code as a CodePen Pen for sharing, but I am unclear which parts of the module workflow CodePen actually supports and which require restructuring.
Constraints I am working under
My understanding is that CodePen executes type="module" scripts natively in the browser, does not support import maps, and therefore cannot resolve bare specifiers the way a bundler does. I also believe the External Resources panel injects classic scripts rather than modules, and that Babel transpilation does not apply to module scripts, so newer syntax may behave differently than in my transpiled local build. I am on a free account, so relative-path asset imports appear to be off the table as well.
Because some of these behaviors may have changed recently, I would like answers grounded in current, verifiable CodePen behavior rather than older forum posts.
Questions
- What is the current recommended way to import npm dependencies inside a module script on CodePen, given the absence of import map support?
- Does enabling Babel on a Pen have any effect on
type="module"code in the JS panel, or is transpilation skipped entirely for modules? - Has CodePen published any update or timeline regarding import map support since it was first requested?