You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
make sure no client files are imported within playwright itself
This would still be our official recommendation. We don't think that e2e tests should import front-end code in Node. Next time component rightfully uses window inline and tests will explode. Mitigating it requires webpack/jsdom-ing the Node which we won't do.
Why shouldn't tests import front-end code? I think there's two different use cases:
Automating an external site, here you'd have no access to the front-end code.
Testing your own site, here you have access to the front-end code and it makes things quite a bit easier not having to duplicate functionality between the actual front-end code and test code. As an example I can use react-router's route object to get a list of all possible routes, which I can then use in tests.
On the other hand, why drop the style files (css/less/scss) only for non-ESM users? Why not ESM users as well?
I understand that you don't want to "jsdom the Node", but if some use cases (e.g. ignoring style files) can be supported without much effort, then why not? It won't support all possible scenarios, but in practice this style files issue seems to be coming up somewhat frequently.
Btw, is there some reasonable workaround? Or simply duplicate relevant code (or manually manage) all that is needed within the e2e tests?
Example
No response
Motivation
Allowing users to reduce duplication by being able to re-use their own front-end code.
Thank you for your involvement. This issue was closed due to limited engagement (upvotes/activity), lack of recent activity, and insufficient actionability. To maintain a manageable database, we prioritize issues based on these factors.
If you disagree with this closure, please open a new issue and reference this one. More support or clarity on its necessity may prompt a review. Your understanding and cooperation are appreciated.
+import { register } from 'node:module';
import type { PlaywrightTestConfig } from '@playwright/test';
+register('@nodejs-loaders/media', import.meta.url);+register('@mdx-js/node-loader', import.meta.url);+
const config: PlaywrightTestConfig = {
// ...
};
export default config;
Code for copying:
import{register}from'node:module';// Node.js ESM loaders for image files and MDX imported by test files// - https://github.com/microsoft/playwright/issues/26822#issuecomment-2692835230register('@nodejs-loaders/media',import.meta.url);register('@mdx-js/node-loader',import.meta.url);
Seems to work so far!
So to import SCSS or other formats in your tests, try to find a Node.js ESM loader (NOT the same as a webpack loader) for your file format, and try using register() from node:module in playwright.config.ts
Activity
pavelfeldman commentedon Sep 4, 2025
Why was this issue closed?
Thank you for your involvement. This issue was closed due to limited engagement (upvotes/activity), lack of recent activity, and insufficient actionability. To maintain a manageable database, we prioritize issues based on these factors.
If you disagree with this closure, please open a new issue and reference this one. More support or clarity on its necessity may prompt a review. Your understanding and cooperation are appreciated.
karlhorky commentedon Sep 9, 2025
Workaround: Node.js ESM Loaders via Customization Hooks
Our workaround is to register Node.js ESM loaders (via Customization Hooks APIs) in
playwright.config.tsfor custom file types imported in our tests -@mdx-js/node-loaderfor MDX files and@nodejs-loaders/mediafor image files:Code for copying:
Seems to work so far!
So to import SCSS or other formats in your tests, try to find a Node.js ESM loader (NOT the same as a webpack loader) for your file format, and try using
register()fromnode:moduleinplaywright.config.tsAlso added to
playwright-tricks: https://github.com/karlhorky/playwright-tricks#import-custom-file-types-in-tests