Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

599
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda