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

Conditional require doesn't include bufferutil #411

Closed
blakeembrey opened this issue Jun 2, 2019 · 11 comments · Fixed by #529
Closed

Conditional require doesn't include bufferutil #411

blakeembrey opened this issue Jun 2, 2019 · 11 comments · Fixed by #529

Comments

@blakeembrey
Copy link

blakeembrey commented Jun 2, 2019

Not particularly an issue with either ncc or webpack but spent way too long debugging after I added apollo to my bundle. The issue is that both Apollo and Puppeteer have optional dependencies on bufferutil, however only the first require throws and the second one just returns an empty object. This results in the runtime usage of bufferutil breaking for the second module, since both these are wrapped in a try..catch already (as they're optional dependencies). This is a feature in Webpack and would need to be changed with strictModuleExceptionHandling but would incur a performance penalty.

Wanted to open this for discussion on how this might be been easier debugged or how it should be handled properly. I'm not familiar with Webpack internals either to understand why this couldn't be turned on in a performant way (e.g. by late assigning to the internal module cache, or is this to support circular requires?).

@guybedford
Copy link
Contributor

@blakeembrey thanks for the clear report on this. I think we should look into ensuring we have the strict behaviour both for correctness and debugging, so I would tend to agree this is a bug. Which version of ncc were you using here? Have you tried with the latest beta release? As I believe the behaviours would be different between the two.

@guybedford guybedford added bug Something isn't working need more info and removed bug Something isn't working labels Jun 3, 2019
@sokra
Copy link
Member

sokra commented Jun 4, 2019

strictModuleExceptionHandling but would incur a performance penalty.

"performance penalty" applies only to older v8 versions. If you are using the latest node.js you should be fine.

@styfle
Copy link
Member

styfle commented Jun 4, 2019

Does aws-sdk depend on ws?

This issue sounds identical to #413

@blakeembrey
Copy link
Author

Definitely an identical issue! I had it from ws + AWS was the second one using buffer util, I think it would have de-duped if they both used as but can check when I’m home.

@blakeembrey
Copy link
Author

blakeembrey commented Jun 5, 2019

@styfle Actually, this was a misdiagnosis. It was from apollo-server (specifically subscriptions-transport-ws) which comes with ws which is not de-duped with the ws that was provided by puppeteer since a major version earlier. Not aws-sdk, it just happened to surface when I added aws-sdk to my bundle. Same issue and root cause though, just wrong package culprit.

@blakeembrey
Copy link
Author

@sokra Since it's AWS Lambda, it'd be node 10 as the latest.

@styfle styfle changed the title Hard to debug issue with Webpack require errors Conditional require doesn't include bufferutil Jun 5, 2019
@Janpot
Copy link
Contributor

Janpot commented Apr 11, 2020

Ran into this as well. I could work around it by making bufferutil external and adding a node_modules folder with just bufferutil.

@styfle Trying to read between the lines here, but is there anything blocking the usage of strictModuleExceptionHandling? Would you accept a PR to add it?

@styfle
Copy link
Member

styfle commented Apr 11, 2020

I read this thread again and I'm not sure how to reproduce the issue.
Can you explain the steps to reproduce so any PR could also include an integration or unit test?

@Janpot
Copy link
Contributor

Janpot commented Apr 12, 2020

@styfle sure, a reproduction is pretty straightforward:

// ./mod.js
throw new Error('kaboom')

// ./index.js
function tryRequire () {
  try {
    require('./mod.js')
    console.log('bad!')
  } catch (err) {
    console.log('good!')
  }
}

tryRequire()
tryRequire()

When you run with node

$ node ./index.js 
  good!
  good!

When you run/build with ncc

$ ncc run -q ./index.js
  good!
  bad!

The solution should be to add strictModuleExceptionHandling: true here, just like next.js does.

@styfle
Copy link
Member

styfle commented Apr 13, 2020

@Janpot Perfect! Let's enable strictModuleExceptionHandling. Would you like to create the PR?

Janpot added a commit to Janpot/ncc that referenced this issue Apr 13, 2020
@Janpot
Copy link
Contributor

Janpot commented Apr 13, 2020

@styfle Sure thing, there you go #529

@kodiakhq kodiakhq bot closed this as completed in #529 Apr 14, 2020
kodiakhq bot pushed a commit that referenced this issue Apr 14, 2020
* enable strictModuleExceptionHandling

Fixes #411

* coverage
musaevonline added a commit to musaevonline/react-animation-ncc that referenced this issue Dec 4, 2021
* enable strictModuleExceptionHandling

Fixes vercel/ncc#411

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

Successfully merging a pull request may close this issue.

5 participants