#Help using compiled dll in nextjs api routes, ffi-napi

22 messages · Page 1 of 1 (latest)

autumn novaBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

wanton oracle
#

Told you before, it just cant find the dll

untold osprey
#

the path is correct

wanton oracle
#

Is there a specific location where it finds the dll from?

untold osprey
#

yes

wanton oracle
#

In your inventory api are you calling a load function?

#

I really think that path variable is messing things up

#

Try printing the path variable to see if its correct before loading

untold osprey
#

it do not work also if i put manually the path

wanton oracle
#

Very weird. If its working for one script it should work for the others too.

#

Anything related to loading or anything in inventory api ?

untold osprey
#

im my api i import it w this
import { TLS_Client } from '@/utils/tls/tls';
and in my other script i use the same import

#

it's 100% that in next it's not viewing the dll file

#

but idk why

wanton oracle
#

Try using the public folder then ig

untold osprey
wanton oracle
#

Idk then

untold osprey
#

bump!
The problem is related to webpack loader for .node file, atm my config is this but i'm getting this error: Conflict: Multiple assets emit different content to the same filename koffi.node

import os from 'os';

export default {
    reactStrictMode: false,
    env: {
        BASE_URL: process.env.BASE_URL,
    },
    webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
        // Trova la regola esistente per i file .node, se presente
        const existingNodeRule = config.module.rules.find((rule) =>
            rule.test instanceof RegExp && /\.node$/.test(rule.test.source)
        );
        console.log(existingNodeRule);

        if (existingNodeRule) {
            console.log("n");
            // Modifica la regola esistente invece di aggiungerne una nuova
            existingNodeRule.use.push({
                loader: "nextjs-node-loader",
                options: {
                    flags: os.constants.dlopen.RTLD_NOW,
                    outputPath: config.output.path,
                },
            });
        } else {
            console.log("y");

            // Se non esiste una regola esistente, crea una nuova regola
            config.module.rules.push({
                test: /\.node$/,
                use: [
                    {
                        loader: "nextjs-node-loader",
                        options: {
                            flags: os.constants.dlopen.RTLD_NOW,
                            outputPath: config.output.path,
                        },
                    },
                ],
            });
        }

        return config;
    },
};

untold osprey
#

i made the solution by mysef, i used koffi because have more stable relases than ffi napi, the problem was that the webpack was not able to solve the ffi napi lib because there was not a compatible version, and using nextjs-node-loader i was able to use .node relases in next
file:next.config.js

import os from 'os';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const arch = os.arch()
const platform = os.platform()
export default {
    reactStrictMode: false,
    env: {
        BASE_URL: process.env.BASE_URL,
    },
    webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
        // Trova la regola esistente per i file .node, se presente
        config.resolve.alias.koffi = path.resolve(`node_modules/koffi/build/koffi/${platform}_${arch}/koffi.node`)
        config.module.rules.push({
            test: /\.node$/,
            use: [
                {
                    loader: "nextjs-node-loader",
                    options: {
                        flags: os.constants.dlopen.RTLD_NOW,
                        outputPath: config.output.path
                    },
                },
            ],
        });

        return config;
    },
};