0

I hope I can make myself be understood...

I'm writing a CEP extension for Adobe products. The good thing is that they include NodeJS - which allows me, for example, to access the filesystem.

Now I want to use a js library that has dependencies on NodeJS (crypto, fs and path). The problem is that within the Adobe extension, all NodeJS functionality is accessible through cep_node.crypto (for example).

The js library that I want to use doesn't know that, naturally. So it tells me:

ERROR in ./node_modules/dynamsoft-javascript-barcode/dist/dbr.min.js Module not found: Error: Can't resolve 'crypto' in '.\node_modules\dynamsoft-javascript-barcode\dist'

The question is - how can I kind of overwrite the reference 'crypto' for example - so it gets accessed by cep_node.crypto?

Stefan R.
  • 438
  • 1
  • 5
  • 22
  • You could overwrite `require` (https://stackoverflow.com/questions/27948300/override-the-require-function) and return `cep_node.crypto` instead of allowing it to do it's thing. – Sergiu Paraschiv Feb 28 '19 at 12:58
  • I tried this solution https://stackoverflow.com/a/34186494/5274022 but the error already appears in the first line, where I call the require ('dynamsoft-javascript-barcode') – Stefan R. Feb 28 '19 at 13:52
  • 1
    Can you share some code? How did you import the module? – yushulx Aug 22 '19 at 23:52
  • 1
    Try to import the module using HTML tag or @StefanR. – yushulx Aug 23 '19 at 00:17

1 Answers1

0

Note this answer is attempting to be helpful (without code in the question it would be impossible to give a direct answer to the problem)

I think it would help to have a good understanding of CEP before you begin incorporating node imports.

CEP extension has a few different elements to it.

  1. The html. Here you build the interface and can load JS files. You would have to make sure node is activated to be able to import.

  2. Js files. Here you can execute your node js files. Not that this area is separate from the actual scripting area (which runs on an antiquated JS engine, you CANNOT load node product with in that engine).

  3. The JSX which runs with in the adobe scripting engine.

In html I load my cep. Then in a js file I can load my node using the cep require: FS as an example:

const fs = cep_node.require('fs');
const csiRun = new CSInterface();

csiRun.evalScript(`buildHtml()`, (returnedImg) => { 
// buildHtml is a method in a JSX that runs with in the adobe scripting //engine.  It cannot handle the node.  I can return a value then do //something like this:

fs.writeFile()
// notice the node module used here.
})
FabricioG
  • 3,107
  • 6
  • 35
  • 74
  • Thanks for your answer and explanation. I'm sorry I kind of abandoned this questions after the first discussion. It is obsolete by now, but yes I agree that an understandment of the different pieces of CEP are essential. – Stefan R. Aug 02 '22 at 07:09