javascriptcanvasnode-webkit

A dynamic link library (DLL) initialization routine failed | nw.js error connecting canvas


I use nw.js and when trying to connect the canvas module (node-canvas), this error appears. Installing a different version of node/canvas didn't help. The error appears when require('canvas') Error image: Error

Uncaught Error: A dynamic link library (DLL) initialization routine failed.
\\?\N:\BOTSer\Protocol\node_modules\canvas\build\Release\canvas.node
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1224:18)
    at Module.load (node:internal/modules/cjs/loader:999:32)
    at Function.Module._load (node:internal/modules/cjs/loader:846:12)
    at Module.require (node:internal/modules/cjs/loader:1023:19)
    at require (node:internal/modules/cjs/helpers:97:18)
    at Object.<anonymous> (N:\BOTSer\Protocol\node_modules\canvas\lib\bindings.js:3:18)
    at Module._compile (node:internal/modules/cjs/loader:1121:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1179:10)
    at Module.load (node:internal/modules/cjs/loader:999:32)
    at Function.Module._load (node:internal/modules/cjs/loader:846:12)
    ```

Solution

  • That module requires a native build that is compatible with your global install of Node.js. If the version of Node in NW.js doesn't match your global install, then the built binary will not work with it. Things always work better when you switch your global Node.js install version to match what is built into NW.js. You can use nvm-windows or nvm to control your global Node version, just be sure to uninstall Node.js first before using a Node Version Manager so you don't have two conflicting global installs. You can check the Node.js version in NW.js by running console.log(process.version);.

    If my assumption is correct then:

    1. Open your app, right-click > inspect > console > process.version > write down the Node version you need > close your app.
    2. Delete node_modules and package-lock.json
    3. Uninstall Node.js globally
    4. Install the correct Node Version Manager for your OS
    5. Use the Node Version Manager to install the version your wrote down in step 1
    6. Do a fresh npm install in your project and try running it again

    Though I'm very confused as to why you would be using the native canvas module with NW.js. Why are you packaging an entire browser with your application that has a canvas built in, and then pulling in a second tool and using it instead? Just use the browser's canvas.