On Sunday, 6 June 2021 at 21:44:44 UTC, NotSpooky wrote:
On Sunday, 6 June 2021 at 04:25:39 UTC, Jack wrote:
I'm trying to use the node_dlang pakckage but the code example from [this repo](https://github.com/NotSpooky/node_dlang/tree/v0.4.11/examples) isn't working

the command ```dub build``` is fine but ```node example.js``` retuns an error saying the module.node is not a valid win32 application. How do I fix this?

[1]: https://github.com/NotSpooky/node_dlang/tree/v0.4.11/examples

Hello, I'm the author of the library.

nice works, thanks for the library!

Indeed I only tested it on 64-bit systems. I can try to make it 32-bit compatible if needed.

for me i think it would be needed, i made everything 64bit so it at least compiled and ran.

Aside from the auto-translated headers, in the case of Windows the repo also includes node.lib compiled for 64-bit, so unless the 32-bit version is added it will also give errors.

I'm pretty sure it does work with electron as I have used it myself.

I managed to compile the module and it passed this test:

```javascript
const nativeModule = require('./module.node');
const assert = require('assert');

assert(nativeModule.ultimate() == 42);
```

The D code looks like this:

```d
import std.stdio : stderr;
import node_dlang;

extern(C):

    void atStart(napi_env env)
    {
        import std.stdio;
        writeln ("Hello from D!");
    }

    int ultimate()
    {
        return 42;
    }

mixin exportToJs! (ultimate, MainFunction!atStart);
```

its builds sucessfully with ```dub``` no arguments (no --arch=x86_mscoff yet because it requires to fix other compilation error). The dub script looks like this:

    ```json
    {
        "authors": [
                "test"
        ],
        "copyright": "Copyright © 2021, test",
        "dependencies": {
                "node_dlang": "~>0.4.11"
        },
        "description": "using electron from D",
        "license": "proprietary",
        "name": "eled",
        "targetType": "dynamicLibrary",
        "targetName" : "module.node",
        "targetPath": "bin"
    }
    ```

then i test with node:

```
node test.js
```

it works fine. However, when I attempt to use it in the prescript within electron, I get this error:

```
A JavaScript error occured in the browser process
---------------------------
Uncaught Exception:
Error: A dynamic link library (DLL) initialization routine failed.

    \\?\C:\Users\001\Desktop\ele\module.node
        at process.func [as dlopen] (VM70 asar_bundle.js:5)
        at Object.Module._extensions..node (VM43 loader.js:1138)
        at Object.func [as .node] (VM70 asar_bundle.js:5)
        at Module.load (VM43 loader.js:935)
        at Module._load (VM43 loader.js:776)
        at Function.f._load (VM70 asar_bundle.js:5)
        at Function.o._load (VM75 renderer_init.js:33)
        at Module.require (VM43 loader.js:959)
        at require (VM50 helpers.js:88)
at Object.<anonymous> (VM88 C:\Users\001\Desktop\ele\preload.js:6)
    ```

the lines of this in the prescript goes like this:

```javascript
const nativeModule = require('./module.node');
const assert = require('assert');

assert(nativeModule.ultimate() == 42);
```

What am I missing?

Reply via email to