Im making an audio enhancer application in electron but as i click on the enhance button in getting this error on console
(node:7587) UnhandledPromiseRejectionWarning: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/adi/spectrum/node_modules/tone/build/esm/core/Global' imported from /home/adi/spectrum/node_modules/tone/build/esm/index.js
at finalizeResolution (node:internal/modules/esm/resolve:264:11)
at moduleResolve (node:internal/modules/esm/resolve:924:10)
at defaultResolve (node:internal/modules/esm/resolve:1137:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
at link (node:internal/modules/esm/module_job:84:36)
(Use `electron --trace-warnings ...` to show where the warning was created)
(node:7587) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 8)
,main js:
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path');
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false, // Consider revisiting for security in future development
preload: path.join(__dirname, 'preload.js') // Optional preload script for additional security (refer to Electron documentation)
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
try {
ipcMain.on('enhance-audio', async (event, filePath) => {
const Tone = await import('tone')
const player = new Tone.Player(filePath).toDestination()
const eq = new Tone.EQ({
low: 0,
mid: 1,
high: 0
}).toDestination()
player.connect(eq)
player.start()
const outputPath = 'enhanced_audio.mp3' // Replace with your logic
event.sender.send('enhancement-complete', outputPath)
})
} catch (error) {
console.log("error",error)
}
this is a main js file, which is responsible for much of the work.
below is renderer.js
const ipcRenderer = require('electron').ipcRenderer
const audioUpload = document.getElementById('audio-upload')
const enhanceButton = document.getElementById('enhance-button')
const outputFilename = document.getElementById('output-filename')
enhanceButton.addEventListener('click', () => {
const filePath = audioUpload.files[0].path
console.log("Sending file path:", filePath);
ipcRenderer.send('enhance-audio', filePath)
})
ipcRenderer.on('enhancement-complete', (event, outputPath) => {
outputFilename.textContent = `Enhanced file: ${outputPath}`
})
I tried Gemini and CHATGPT and tried to re import libs but its working
1