0

I am importing fluent-ffmpeg with: import ffmpeg from 'fluent-ffmpeg' in one file.

After running webpack, I receive this error: Uncaught Exception: ReferenceError: fluent is not defined

I looked inside the transpiled file and I found fluent-ffmpeg included like so: function(e,t){e.exports=fluent-ffmpeg}

After changing the line to read: function(e,t){e.exports=require("fluent-ffmpeg")} the programs work.

Is there a way to configure webpack to correctly require fluent-ffmpeg when transpiling?

Edit: I am using this electron react webpack boilerplate to build a desktop application - https://github.com/chentsulin/electron-react-boilerplate

Update: I've created a repo to show the bug - https://github.com/the4dpatrick/congenial-barnacle. The difference between electron-react-boilerplate and this repo can be seen in a single commit

To see bug:

  • npm i
  • packaging the electron app (npm run package)
  • opening the app which is under the release dir.
  • Alert opens with error
Patrick
  • 1,410
  • 2
  • 19
  • 37
  • are you closing the opening `'`? i.e. `import ffmpeg from 'fluent-ffmpeg'` – Mauricio Poppe May 29 '16 at 00:52
  • Yes, and even changing the line to `const ffmpeg = require("fluent-ffmpeg")` results in the same. Edit: In the question I just had a typo where I left out the trailing `'` – Patrick May 29 '16 at 00:56
  • 1
    Webpack is a client side module bundler, even if you manage to create the bundle it won't work on a browser since `fluent-ffmpeg` uses node's `os` and `child_process` modules, am I right? – Mauricio Poppe May 29 '16 at 01:15
  • @MauricioPoppe I'm using this electron react boilerplate - https://github.com/chentsulin/electron-react-boilerplate. It's for a desktop application – Patrick May 29 '16 at 07:58

1 Answers1

1

I was able to solve the issue by simply setting the output.libraryTarget setting within webpack.config.electron.js file to commonjs2.

output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    libraryTarget: 'commonjs2'
  },

For further details read: chentsulin/electron-react-boilerplate#232

Patrick
  • 1,410
  • 2
  • 19
  • 37
  • where the file `webpack.config.electron.js` should be placed ? is it possible to set this in `webpack.config.base.js` ? – crak Jun 12 '17 at 14:16