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

[Bug]: Import/Require via globalSetup module stopped resolving in v1.45.0 #31725

Open
mehibbs opened this issue Jul 17, 2024 · 6 comments
Open

Comments

@mehibbs
Copy link

mehibbs commented Jul 17, 2024

Version

1.45.0

Steps to reproduce

Something changed between Playwright 1.44.1 and 1.45.0 which has broken our current setup, and I haven't spotted anything related in the changelog.

Essentially I can distil the problem down to this:

playwright.config.ts

import {defineConfig} from '@playwright/test';

export default defineConfig({
    globalSetup: require.resolve('./GlobalSetup')
});

GlobalSetup.ts

async function GlobalSetup(): Promise<void> {
    await import('./config');
}
export default GlobalSetup;

config.js

console.log('config');
const otherConfig = require('./other-config');
module.exports = {};

other-config.js

console.log('other-config');
module.exports = {};

Where in Playwright@1.44.1 we see "other-config" being printed - i.e. the second CJS module is loaded, where-as in Playwright@1.45.0 we hang on require('./other-config').

Granted it's a somewhat odd setup, however, it is a breaking change?

Moving entirely to ESM isn't practical at the moment in the real setup, so I'm hoping this is indeed a bug.

Expected behavior

I expect the second module "other-config" to be resolved and loaded.

Actual behavior

Running hangs on loading the second CJS module.

Additional context

No response

Environment

System:
    OS: Windows 11 10.0.22631
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
    Memory: 11.98 GB / 31.68 GB
  Binaries:
    Node: 20.13.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Bash: 5.1.16
  npmPackages:
    @playwright/test: ^1.45.0 => 1.45.0
@dgozman
Copy link
Contributor

dgozman commented Jul 18, 2024

This is related to unconditional registration of the ESM loader. When you await import('./config'), the ESM loader kicks in. It seems like there is a bug in Node.js where ESM loader hangs, perhaps this one - nodejs/node#50948. Let's wait for the resolution of the upstream issue.

@chrisbottin
Copy link

I think this issue was caused by the removal of the Babel plugin @babel/plugin-transform-dynamic-import in
#31285

@dgozman
Copy link
Contributor

dgozman commented Jul 19, 2024

@chrisbottin You are right, this was probably the exact change that triggered this behavior. However, the problem that should be fixed is that the ESM loader hangs.

@chrisbottin
Copy link

@dgozman Yes I understand it but is it possible to have an interim solution in Playwright while the ESM loader is getting fixed?

@mehibbs
Copy link
Author

mehibbs commented Jul 23, 2024

@dgozman Would you be able to confirm whether a solution (e.g. config setting to enable the babel plugin again) is being considered? As we're currently fixed on version 1.44.1 temporarily and will need to soon make a decision as to the best course of action.

@dgozman
Copy link
Contributor

dgozman commented Jul 23, 2024

@mehibbs There are no plans for the workaround right now. I'd recommend to avoid await import('./config') and replace it with static import config from './config' at the top of the file.

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

No branches or pull requests

3 participants