Help using compiled dll in nextjs api routes, ffi-napi
Answered
Sloth bear posted this in #help-forum
Original message was deleted.
Answered by Sloth bear
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
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;
},
};21 Replies
Told you before, it just cant find the dll
@Clown Told you before, it just cant find the dll
Sloth bear
yeah but i still haven't found a solution...
the path is correct
Is there a specific location where it finds the dll from?
Sloth bear
yes
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
it do not work also if i put manually the path
Very weird. If its working for one script it should work for the others too.
Anything related to loading or anything in inventory api ?
Sloth bear
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
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
Try using the public folder then ig
@Clown Try using the public folder then ig
Sloth bear
same error
Idk then
Sloth bear
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
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;
},
};Sloth bear
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
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;
},
};Answer