Search code examples
angularelectronfschild-processfluent-ffmpeg

Can't resolve fs, child_process


I know there are many other questions reporting very similar situations, but not exactly, and none helped me.

I'm trying to use the 'ffmpeg-static-electron' dependency on Angular Electron.

On my yt-dl branch on my forked https://github.com/arcovoltaico/angular-electron after npm install I will get errors from dependencies (look at the end of this text)

Adding this to the angular root "package.json" file has no effect. "browser": { "fs": false, "path": false, "os": false}

I am only successful when I add it, straight into the dependency's own package.json :

On fluent-ffmpeg-corrected "browser": { "fs": false, "child_process": false }, and this on isexe:

"browser": { "fs": false, }, (edited)

Obviously editing a downloaded dependency is not a good practice. Is there another way to fix it within our code? Thanks a lot

Errors:

Compiled with problems:X

ERROR in ./node_modules/fluent-ffmpeg-corrected/lib/capabilities.js 4:9-22

Module not found: Error: Can't resolve 'fs' in '/Users/jordi.alhambraherraiz/MyRepos/U-Vox/angular-electron/node_modules/fluent-ffmpeg-corrected/lib'


ERROR in ./node_modules/fluent-ffmpeg-corrected/lib/ffprobe.js 4:12-42

Module not found: Error: Can't resolve 'child_process' in '/Users/jordi.alhambraherraiz/MyRepos/U-Vox/angular-electron/node_modules/fluent-ffmpeg-corrected/lib'


ERROR in ./node_modules/fluent-ffmpeg-corrected/lib/processor.js 4:12-42

Module not found: Error: Can't resolve 'child_process' in '/Users/jordi.alhambraherraiz/MyRepos/U-Vox/angular-electron/node_modules/fluent-ffmpeg-corrected/lib'


ERROR in ./node_modules/fluent-ffmpeg-corrected/lib/processor.js 8:9-22

Module not found: Error: Can't resolve 'fs' in '/Users/jordi.alhambraherraiz/MyRepos/U-Vox/angular-electron/node_modules/fluent-ffmpeg-corrected/lib'


ERROR in ./node_modules/fluent-ffmpeg-corrected/lib/recipes.js 4:9-22

Module not found: Error: Can't resolve 'fs' in '/Users/jordi.alhambraherraiz/MyRepos/U-Vox/angular-electron/node_modules/fluent-ffmpeg-corrected/lib'


ERROR in ./node_modules/fluent-ffmpeg-corrected/lib/utils.js 4:11-40

Module not found: Error: Can't resolve 'child_process' in '/Users/jordi.alhambraherraiz/MyRepos/U-Vox/angular-electron/node_modules/fluent-ffmpeg-corrected/lib'


ERROR in ./node_modules/isexe/index.js 1:9-22

Module not found: Error: Can't resolve 'fs' in '/Users/jordi.alhambraherraiz/MyRepos/U-Vox/angular-electron/node_modules/isexe'


ERROR in ./node_modules/isexe/mode.js 4:9-22

Module not found: Error: Can't resolve 'fs' in '/Users/jordi.alhambraherraiz/MyRepos/U-Vox/angular-electron/node_modules/isexe'


ERROR in ./node_modules/isexe/windows.js 4:9-22

Module not found: Error: Can't resolve 'fs' in '/Users/jordi.alhambraherraiz/MyRepos/U-Vox/angular-electron/node_modules/isexe'

Solution

  • Generally the easiest way to fix issues with unmaintained dependencies is to fork them on github and use your customized version.

    fs and child_process are internal node functions that are available in nodejs but not in the browser.

    Electron uses a browser as renderer process, so your fix "browser": { "fs": false, "child_process": false } will work for webpack when packaging things but it's high likely that the dependency won't work as you expect.

    In this answer from zeffiro you can find more details about how electron handles processes.

    Since fluent-ffmpeg-corrected is not available anymore on github and was never updated you may look for more supported dependencies, or if you want to stick with this one you can copy the sources from node_modules folder, edit the package.json file and push your version with costomized dependencies ad use it in your project with npm i github:<UserName>/<RepoName>. I think there are no better ways to do it.

    Anyway the communication process between the main process and the renderer process is still to be managed and the answer from zeffiro may help you.