Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a node project that uses the module native-node-printer with edge-js module (for windows platform) when trying to package it using pkg module it gives this error :

Warning Cannot resolve ' ../../${ process.env.NNP_PACKAGE } ' C:\VisualSutdioCode\ticketing-2019\pkg\print-scan-server\node_modules\node-native-printer\src\windows_printer.js Dynamic require may fail at run time, because the requested file is unknown at compilation time and not included into executable. Use a string literal as an argument for 'require', or leave it as is and specify the resolved file name in 'scripts' option.

the edge-js is refereneced in the native-node-printer.

Anyone can help me on that ?

best regards,

edit the "node_modules\node-native-printer\src\windows_printer.js" as below

// const edge = require(`../../${process.env.NNP_PACKAGE}`); 
const edge = require(`edge-js`);
// const dllPath = fs.realpathSync(__dirname + '/../lib/windows/windows_printer.dll').replace('.asar', '.asar.unpacked');
const dllPath = fs.realpathSync(process.cwd() + '/lib/windows/windows_printer.dll').replace('.asar', '.asar.unpacked');

after the app is packaged using pkg, copy the node_modules/node-native-printer/lib folder to your app root. your directory structure should be like as below

  • app.exe
  • if you don't updated the dllPath you probably will get an error similar to the one below

    Error: Could not load file or assembly 'file:///E:\snapshot\print-server\node_modules\node-native-printer\lib\windows\windows_printer.dll' or one of its dependencies. The system cannot find the file specified.
        at Object.func (E:\snapshot\print-server\node_modules\edge-js\lib\edge.js:182:17)
        at WinPrinter.listPrinters (E:\snapshot\print-server\node_modules\node-native-printer\src\windows_printer.js:24:19)
        at E:\snapshot\print-server\app.js:9:13
        at Layer.handle [as handle_request] (E:\snapshot\print-server\node_modules\express\lib\router\layer.js:95:5)
        at next (E:\snapshot\print-server\node_modules\express\lib\router\route.js:137:13)
        at Route.dispatch (E:\snapshot\print-server\node_modules\express\lib\router\route.js:112:3)
        at Layer.handle [as handle_request] (E:\snapshot\print-server\node_modules\express\lib\router\layer.js:95:5)
        at E:\snapshot\print-server\node_modules\express\lib\router\index.js:281:22
        at Function.process_params (E:\snapshot\print-server\node_modules\express\lib\router\index.js:335:12)
        at next (E:\snapshot\print-server\node_modules\express\lib\router\index.js:275:10)
    ^Cnpm ERR! code ELIFECYCLE
    npm ERR! errno 3221225786
    npm ERR! print-server@1.0.0 start: `node app.js`
    npm ERR! Exit status 3221225786
    npm ERR!
    npm ERR! Failed at the print-server@1.0.0 start script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    

    Hope this helps!

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.