node-bindings: getFileName cannot read property of undefined

Seeing the below when using https://github.com/jostrander/mouse-forward-back in our project (https://github.com/lbryio/lbry-desktop/commit/cd8436c1dd1de374f8c2a9ce962502303179fe32). We are using webpack 3.

      at Function.getFileName (webpack-internal:///./node_modules/bindings/bindings.js:176:16)
      at bindings (webpack-internal:///./node_modules/bindings/bindings.js:82:48)
      at eval (webpack-internal:///./node_modules/mouse-forward-back/mouse-forward-back.js:3:82)
      at Object../node_modules/mouse-forward-back/mouse-forward-back.js (/home/tom/lbry-desktop/dist/main/main.js:739:1)
      at __webpack_require__ (/home/tom/lbry-desktop/dist/main/main.js:655:30)
      at fn (/home/tom/lbry-desktop/dist/main/main.js:65:20)
      at __webpack_exports__.a.appState (webpack-internal:///./src/main/createWindow.js:18:24)
      at App.eval (webpack-internal:///./src/main/index.js:120:91)
      at Generator.next (<anonymous>)
      at step (webpack-internal:///./src/main/index.js:24:191)

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 11
  • Comments: 18 (1 by maintainers)

Commits related to this issue

Most upvoted comments

This s a huge issue. Took me hours to figure out a workaround…

same here. I was using node-speaker in a React project with Webpack. In webpack.config.js I set node: { fs: 'empty', console: true, net: 'empty', tls: 'empty' }, it shows the following error:

Uncaught TypeError: Cannot read property 'indexOf' of undefined
    at Function.getFileName (bindings.js:180)
    at bindings (bindings.js:84)
    at eval (index.js:9)
    at Object../node_modules/speaker/index.js (Panel.bundle.js:7426)
    at __webpack_require__ (Panel.bundle.js:724)
    at fn (Panel.bundle.js:101)
    at Object.eval (AWSPolly.js:11)
    at eval (AWSPolly.js:50)
    at Object../src/components/App/AWSPolly.js (Panel.bundle.js:7756)
    at __webpack_require__ (Panel.bundle.js:724)

A follow-up question: can node-speaker be used in a front-end project?

If I set target: "node" in webpack.config.js, it would show Uncaught ReferenceError: require is not defined. The reason is bindings.js has var fs=require("fs"). In Webpack, by setting target:"node", it will not pack fs and require. But these two do not work for browsers. On the other hand, if set target:"web", it would show fs module not found.

I tried many ways but had not solve it yet. I hope I made myself clear.

I’m also encountering this error in a project that uses better-sqlite3 (depends on this).

Problem is that if your optimizer is too aggressive, this call will get removed:

dummy.stack; So the stack getter is not called which causes the error mentioned above.

Changing the optimizer settings not to optimize such code or exclude drivelist by setting it as external as mentioned above will also work.

I fixed it by changing the terser options like this in webpack configuration file;

optimization: {
        minimizer: [
            new TerserPlugin({
                cache: true,
                parallel: true,
                terserOptions: {
                    compress: {
                        reduce_vars: false
                    }
                }
              }),
        ]
    },

I hit the same issue today. Using for electron. Is there any workaround other than changing target or removing fs, because, i need those two

@etylermoss @Stefano1990 @TooTallNate See https://github.com/TooTallNate/node-bindings/pull/66. I proposed a fix for this problem, which does resolve the issues I have.

Was no fix found for this?> I’m experiencing the issue with node-midi

I find a solution for my Electron + Vue app

pluginOptions: {
    electronBuilder: {
      externals: ['speaker'], // add this line
      ...

Had the same issue with drivelist in an electron app using webpack. Worked fine in dev but not built for production. Finally found some hints on similar issues and found that adding “drivelist” to externals in webpack config solved the issue for us. Hope it helps

I’ve encountered this issue using Rollup. It seems to be caused by rollup deleting this line: https://github.com/TooTallNate/node-bindings/blob/c8033dcfc04c34397384e23f7399a30e6c13830d/bindings.js#L172

That dummy.stack; line is what actually causes the prepareStackTrace() to run. This seems to be some mysterious lazy-evaluation insanity? I guess some optimisation pass somewhere in the bundler makes the not-unreasonable decision that this line can’t have side effects and eats it.

If you change the line to dummy = dummy.stack; then things start working as expected. I suggest refactoring this whole function such that its dataflow no longer relies on mysticism and goat sacrifice.