Собираю проект в бандл при помощи Webpack (Ver: 5).
Webpack config:
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const WebpackObfuscator = require('webpack-obfuscator');
const webpack = require('webpack');
const { constants } = require('os');
/**
*
* @param {*} env
* @param {*} argv
* @returns {import('webpack').Configuration}
*/
module.exports = (env, argv) => {
return {
mode: 'development' || 'production',
entry: './src/index.ts',
target: 'node',
output: {
filename: 'index.js',
path: path.resolve('./bundle'),
library: {
type: 'commonjs2',
},
libraryTarget: 'commonjs2',
clean: true,
},
resolve: {
extensions: ['.ts', '.js', '.node'],
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(node)$/,
loader: 'node-loader',
options: {
name: '[name]_[contenthash].[ext]',
flags: constants.dlopen.RTLD_NOW,
},
},
],
},
optimization: {
splitChunks: false,
minimize: false,
minimizer: [
new TerserPlugin({
minify: TerserPlugin.swcMinify,
terserOptions: {
format: { comments: false },
},
extractComments: false,
}),
],
},
plugins: [
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
],
};
};
При запуске после сборки выдаёт ошибку:
Error:Secret-Path\bundle\node_modules/onnxruntime-node/bin/napi-v3/win32/x64/onnxruntime_binding.node is not a valid Win32 application.
Secret-Path\bundle\node_modules/onnxruntime-node/bin/napi-v3/win32/x64/onnxruntime_binding.node
at eval (webpack://project-name/./node_modules/onnxruntime-node/bin/napi-v3/win32/x64/onnxruntime_binding.node?:6:9)
at ./node_modules/onnxruntime-node/bin/napi-v3/win32/x64/onnxruntime_binding.node (Secret-Path\bundle\index.js:389:1)
at __webpack_require__ (Secret-Path\bundle\index.js:1583:42)
at webpackContext (webpack://project-name/./node_modules/onnxruntime-node/bin/napi-v3/_sync_^\.\/.*\/.*\/onnxruntime_binding\.node$?:13:9)
at eval (webpack://project-name/./node_modules/onnxruntime-node/dist/binding.js?:9:127)
at ./node_modules/onnxruntime-node/dist/binding.js (Secret-Path\bundle\index.js:431:1)
at __webpack_require__ (Secret-Path\bundle\index.js:1583:42)
at eval (webpack://project-name/./node_modules/onnxruntime-node/dist/backend.js?:18:19)
at ./node_modules/onnxruntime-node/dist/backend.js (Secret-Path\bundle\index.js:420:1)
at __webpack_require__ (Secret-Path\bundle\index.js:1583:42)
Node.js v20.17.0
Файлы после сборки:
Как это исправить?
Node: v20.17.0 (x64)
Windows: 10 Pro x64