Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getFileName cannot read property of undefined #54

Open
tzarebczan opened this issue Jan 31, 2019 · 18 comments
Open

getFileName cannot read property of undefined #54

tzarebczan opened this issue Jan 31, 2019 · 18 comments

Comments

@tzarebczan
Copy link

Seeing the below when using https://github.com/jostrander/mouse-forward-back in our project (lbryio/lbry-desktop@cd8436c). 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)
@TooTallNate
Copy link
Owner

What is webpack-internal://?

@btakita
Copy link

btakita commented May 11, 2019

I'm also getting the issue.

It looks like

Error.captureStackTrace(dummy) is setting dummy to have an undefined stack member.

https://github.com/TooTallNate/node-bindings/blob/master/bindings.js#L171

I added some debug logic:

    console.debug('getFileName|debug|3', {
      dummy,
      'dummy.stack': dummy.stack,
    })
getFileName|debug|3 { dummy: {}, 'dummy.stack': undefined }

@jguo1002
Copy link

jguo1002 commented Jul 12, 2019

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.

@gencer
Copy link

gencer commented Aug 17, 2019

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

@select-this
Copy link

select-this commented Oct 8, 2019

For what it's worth, I've also hit this issue when trying to include a local native node module that uses bindings in Electron (no webpack involved here). Haven't figured out a workaround yet.

@bromix
Copy link

bromix commented Oct 17, 2019

For what it's worth, I've also hit this issue when trying to include a local native node module that uses bindings in Electron (no webpack involved here). Haven't figured out a workaround yet.

exact the same problem here.

@warpdesign
Copy link

Same error :/

@ghost
Copy link

ghost commented Jan 23, 2020

Facing same issue, has anyone come up with a solution or workaround? Thanks!

@etylermoss
Copy link

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

@Stefano1990
Copy link

Same issue here as @ajmar with electron and better-sqlite3 as well.

@ChrisKitching
Copy link

ChrisKitching commented Apr 10, 2020

I've encountered this issue using Rollup. It seems to be caused by rollup deleting this line:

dummy.stack;

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.

@pjebs
Copy link

pjebs commented Apr 16, 2020

I've got the same issue with rollup (bundler) and an electron app. A recent PR supposedly made it work with electron, but I don't think it factored in bundling.

See: #29 (comment)

@pverscha
Copy link

pverscha commented May 11, 2020

@etylermoss @Stefano1990 @TooTallNate See #66. I proposed a fix for this problem, which does resolve the issues I have.

@d4kris
Copy link

d4kris commented May 14, 2020

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

@warpdesign
Copy link

warpdesign commented May 16, 2020

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
                    }
                }
              }),
        ]
    },

@stoefln
Copy link

stoefln commented Jan 25, 2021

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

@Pckool
Copy link

Pckool commented Mar 11, 2021

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

@wxfred
Copy link

wxfred commented Mar 22, 2022

I find a solution for my Electron + Vue app

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests