7

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

Alam Téllez
  • 178
  • 9

0 Answers0