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)
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.jsI setnode: { fs: 'empty', console: true, net: 'empty', tls: 'empty' }, it shows the following error:A follow-up question: can node-speaker be used in a front-end project?
If I set
target: "node"inwebpack.config.js, it would showUncaught ReferenceError: require is not defined. The reason is bindings.js hasvar fs=require("fs"). In Webpack, by settingtarget:"node", it will not packfsandrequire. But these two do not work for browsers. On the other hand, if settarget:"web", it would showfs 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:
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;
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
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
externalsin webpack config solved the issue for us. Hope it helpsI’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 theprepareStackTrace()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.