Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

595
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda