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

598
Views
How to import file from npm package that is not part of package.json exports

I'm trying to import the content of a file that is not listed as an export by it's package's package.json file. What the library (yargs) suggests to do is to import the file through something like unpkg:

import Yargs from 'https://unpkg.com/yargs@17.5.1/browser.mjs';

But since I'm building a chrome extension it violates a policy:

Refused to load the script 'https://unpkg.com/yargs@17.5.1/browser.mjs' because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

The structure of the installed package is

yargs
-- build
  -- stuff
-- helpers
  -- index.cjs
-- package.json
-- index.cjs
-- index.mjs
-- yargs.cjs
-- ...
-- browser.mjs

But since package.json is as follows:

{// stuff
"exports": {
    ".": {
      "import": "./index.mjs",
      "require": "./index.cjs"
    },
    "./helpers": {
      "import": "./helpers.mjs"
    },
    "./yargs": {
      "require": "./yargs.cjs"
    }
  },
//}

browser.mjs is inaccessible.

Is there any way to skip package.json export configuration and load the file directly? I know it's right there but for some reason it cannot be resolved.

The problem goes deeper since the same happens with a dependency of yargs but I figured that if I can resolve this one, the other one is resolved in the same manner.

Thanks

about 4 years ago · Juan Pablo Isaza
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!