KonnorRogers / shadow-dom-testing-library

An extension of DOM-testing-library to provide hooks into the shadow dom
MIT License
98 stars 2 forks source link

Can't work with Storybook + Webpack 5 starting 1.13.0 #34

Closed eric-burel closed 2 years ago

eric-burel commented 2 years ago

Hi,

Sorry in advance for the vague issue because I couldn't build a repro and the error logs are hard to decipher, but here it is:

Samples of the error log:

ModuleNotFoundError: Module not found: Error: Can't resolve 'stream' in '/home/ubuntu/webapp/node_modules/jsdom/lib/jsdom/living/helpers'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

ModuleNotFoundError: Module not found: Error: Can't resolve 'perf_hooks' in '/home/ubuntu/webapp/node_modules/jsdom/lib/jsdom'
    at /home/ubuntu/webapp/node_modules/webpack/lib/Compilation.js:2016:28
    at /home/ubuntu/webapp/node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (/home/ubuntu/webapp/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)

Any idea where to start?

KonnorRogers commented 2 years ago

Yea so you'd have to configure the storybook webpack config.

https://storybook.js.org/docs/react/configure/overview

There's a number of guides on poly filling Node fallbacks manually, or you could add this plugin:

https://www.npmjs.com/package/node-polyfill-webpack-plugin

eric-burel commented 2 years ago

Thanks for the hint I will try that, however what is the reason for the need for polyfills in the first place? I'd like to avoid them as much as possible if they are not strictly needed

KonnorRogers commented 2 years ago

Right now they're needed because the shadow-dom serializer that prints to the console uses JSDOM. Perhaps there's a different way to serialize the DOM since this could be a blocker for people running the test suite on a browser environment.

KonnorRogers commented 2 years ago

In fact, as I'm looking at it, I think a normal DOMParser may do the trick here...

KonnorRogers commented 2 years ago

@eric-burel give v1.6.2 a whirl and let me know if that fixes it for you. If not feel free to reopen this.

eric-burel commented 2 years ago

Perfect, much thanks for the very quicky fix!