javascriptimportdenoopenpgp.js

How to import openpgp.js in Deno?


As OpenPGP.js hasn't published in JSR yet, I need to import it via HTTP if I don't want to clone it to my local. Using:

import 'https://unpkg.com/browse/openpgp@6.0.1/dist/openpgp.js';

yields:

error: Expected a JavaScript or TypeScript module, but identified a Unknown module. Importing these types of modules is currently not supported.

It does publish on deno.land/x, but using:

import 'https://deno.land/x/openpgp@v6.0.1/mod.js';

yields "Module not found".

My ultimate goal is to upload Google API credentials on GitHub, via encrypting and decrypting the credentials.


Solution

  • The deno.land/x version doesn't seem right, because it uses extensionless imports. Did you try the npm version? Deno supports NPM packages, so JSR is not needed.

    Alternatively, you can import the ESM browser version from https://cdn.jsdelivr.net/npm/openpgp@6.0.1/dist/openpgp.mjs