I was trying to integrate document viewer tabs in an electron app. First I tried using native bindings to create a node addon but the IPC between main and renderer processes along with mutexes was outweighing the fast processing. Now I tried using the wasm version but I get this error during webpack compilation when trying to build ERROR in ./node_modules/mupdf/dist/mupdf-wasm.js 114:51-81 Module not found: Error: Can't resolve './' in 'D:vsprojectsElectronElectronPDFnode_modulesmupdfdist' resolve './' in 'D:vsprojectsElectronElectronPDFnode_modulesmupdfdist' Parsed request is a directory using description file: D:vsprojectsElectronElectronPDFnode_modulesmupdfpackage.json (relative path: ./dist) using description file: D:vsprojectsElectronElectronPDFnode_modulesmupdfpackage.json (relative path: ./dist) as directory existing directory D:vsprojectsElectronElectronPDFnode_modulesmupdfdist using description file: D:vsprojectsElectronElectronPDFnode_modulesmupdfpackage.json (relative path: ./dist) using path: D:vsprojectsElectronElectronPDFnode_modulesmupdfdistindex using description file: D:vsprojectsElectronElectronPDFnode_modulesmupdfpackage.json (relative path: ./dist/index)
from here
if (ENVIRONMENT_IS_WORKER) { scriptDirectory = nodePath.dirname(scriptDirectory) + '/'; } else { // EXPORT_ES6 + ENVIRONMENT_IS_NODE always requires use of import.meta.url, // since there's no way getting the current absolute path of the module when // support for that is not available. scriptDirectory = require('url').fileURLToPath(new URL('./', import.meta.url)); // includes trailing slash }
I would appreciate any direction, thanks.
webpack.config.js
{
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development', // Set this to 'production' for production builds
entry: './src/renderer/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
devtool: 'source-map', // Use a safer source map option
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.mjs',],
alias: {
'./': path.resolve(__dirname, 'node_modules/mupdf/dist'),
},
},
module: {
rules: [
{
test: /.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /.css$/,
use: [
'style-loader',
'css-loader',
'postcss-loader',
],
},
{
test: /.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
},
{
test: /mupdf-wasm.js$/,
type: 'javascript/esm', // or 'javascript/dynamic'
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
}),
],
target: 'electron-main',
};
ts.config.json
{
"compilerOptions": {
"target": "ES6",
"module": "NodeNext",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"jsx": "react",
"jsxFactory": "React.createElement",
"jsxFragmentFactory": "React.Fragment",
"skipLibCheck": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"types": [ "node", "react", "react-dom" ],
"typeRoots": [
"./node_modules/@types",
"src"
]
},
"include": [ "src", "src/main/preload.ts", "src/renderer/wasm/pdf.worker.mjs" ]
}