Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.1k stars 1.16k forks source link

Not a valid Win32 Application #1533

Closed grumbaut closed 4 years ago

grumbaut commented 4 years ago

Issue or Feature

I'm using node-canvas along with PDF.js to transform PDFs into images, as shown in their pdf2png example.

I included this in a command line tool that was built and published on a Mac, and can run it just fine there. However, on Windows, I'm getting the following error:

internal/modules/cjs/loader.js:1208
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: \\?\C:\Users\grumbaut\Documents\books\westcivbr\node_modules\canvas\build\Release\canvas.node is not a valid Win32 application.
\\?\C:\Users\grumbaut\Documents\books\westcivbr\node_modules\canvas\build\Release\canvas.node
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1208:18)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\Users\grumbaut\Documents\books\westcivbr\node_modules\canvas\lib\bindings.js:3:18)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)

I'm using NVM and have confirmed that I have a 64-bit version of both Windows and Node installed. I also tested this out using a 32-bit version of Node and am still getting the same errors.

This is a blocker for a few people, so any help would be appreciated.

Steps to Reproduce

Your Environment

zbjornson commented 4 years ago

My guess is it's still something to do with NVM and 32 vs. 64-bit. If you're using npm, you can try overriding the target arch with npm install canvas --target_arch=ia32 or x64 (last I checked yarn does not forward flags).

aspasov86 commented 4 years ago

I'm having the same problem... Tried npm install canvas --target_arch=ia32 and it didn't work for me.

zbjornson commented 4 years ago

There's not enough info here to troubleshoot, so I'm going to close this for now.

If anyone wants to troubleshoot further, can you please post:

node -p "process.arch"

and

const fs = require("fs");
const path = require("path");
const cnode = path.join(require.resolve("canvas"), "../build/Release/canvas.node");
const fd = fs.openSync(cnode);
const b = Buffer.alloc(4);
fs.readSync(fd, b, 0, 4, 60);
const pe_addr = b.readUInt32LE(0);
fs.readSync(fd, b, 0, 2, pe_addr + 4);
const type = b.readUInt16LE(0);
console.log(type.toString(16));

That will print one of the values here, which should be 8664 (64-bit) or 14c (32-bit).

LoganDark commented 3 years ago

@zbjornson I'm having this issue with another library, fs-ext - my Node installation is 64-bit and so is the binary:

image

Past that, are there any extra troubleshooting steps that you might have? I understand if you don't have any since this is a different library - but anything helps. Thanks!

LoganDark commented 3 years ago

Nevermind, node-loader is being really, really dumb

image

Disregard my previous comment lol

zbjornson commented 3 years ago

@LoganDark could you share some more info on what was going wrong so I can add it to the installation troubleshooting guide please? There have been quite a few issues opened for "not a valid Win32 application" that weren't due to 64/32-bit mismatches. Maybe some were due to node-loader.

LoganDark commented 3 years ago

@LoganDark could you share some more info on what was going wrong so I can add it to the installation troubleshooting guide please? There have been quite a few issues opened for "not a valid Win32 application" that weren't due to 64/32-bit mismatches. Maybe some were due to node-loader.

It was fixed by this PR https://github.com/electron-userland/electron-forge/pull/2449 that was just recently merged. Making the patch manually fixes the issue