Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Can I import npm packages dynamically from CDNs in Webpack?

I need to require a different version of Zoid npm package dynamically in my JS bundle, depending on a variable. So for example:

if (isLatestVersion) {
  zoid = await import('https://unpkg.com/zoid@9.0.80/index.js')
} else {
  zoid = await import('https://unpkg.com/zoid@9.0.31/index.js')
}

However when I try the above I get this error:

script.js:2 Uncaught (in promise) Error: Cannot find module 'https://unpkg.com/zoid@9.0.80/index.js'
    at webpackMissingModule (script.js:2)

Presumably this is because I don't have zoid defined in my package.json.

So basically my question is, is there's a way to import libraries from a CDN such as unpkg.com or skypack.dev, using Webpack's dynamic imports (aka code splitting)?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The way I ended up solving this was by adding two versions of the same package in my package.json. So I ran these commands:

yarn add zoid9080@npm:zoid@9.0.80
yarn add zoid9031@npm:zoid@9.0.31
yarn remove zoid

Then I imported these two packages statically, since I didn't actually need dynamic importing, and the code ended up being simpler as well:

import zoid from 'zoid9080';
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!