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] After executing the electron test, the error "Cannot read properties of undefined (reading 'require')" is reported #28048

Closed
1 task done
duan602728596 opened this issue Nov 9, 2023 · 3 comments · Fixed by #28499 or opossum-tool/OpossumUI#2389
Assignees
Labels

Comments

@duan602728596
Copy link

System info

  • Playwright Version: v1.39.0
  • Operating System: All
  • Browser: Electron
  • Other info: Electron Version: v28

After I upgraded the project's Electron version to v28, if I execute the test, I get an error:

image

Versions less than 28 do not have this error:

image

Source code

  • I provided exact source code that allows reproducing the issue locally.

Link to the GitHub repository with the repro
https://github.com/duan602728596/electron-v28-bug-demo

Steps

  • npm install
  • npm run test

Expected

Run test success.

Actual

Run test failed.

@mxschmitt
Copy link
Member

mxschmitt commented Nov 9, 2023

Full stack:

  1) index.test.mjs:9:3 › App › Should render #app dom ─────────────────────────────────────────────

    Error: TypeError: Cannot read properties of undefined (reading 'require')

        at <anonymous>:1:20
        at CRExecutionContext.rawEvaluateHandle (/Users/maxschmitt/Developer/tmp/electron-v28-bug-demo/node_modules/playwright-core/lib/server/chromium/crExecutionContext.js:58:33)
        at runNextTicks (node:internal/process/task_queues:60:5)
        at processImmediate (node:internal/timers:447:9)
        at LongStandingScope._race (/Users/maxschmitt/Developer/tmp/electron-v28-bug-demo/node_modules/playwright-core/lib/utils/manualPromise.js:98:14)
        at CRSession.<anonymous> (/Users/maxschmitt/Developer/tmp/electron-v28-bug-demo/node_modules/playwright-core/lib/server/electron/electron.js:68:13)

Good npm install electron-nightly@28.0.0-nightly.20230828
Bad npm install electron-nightly@28.0.0-nightly.20230831

RANGE: electron/electron@v28.0.0-nightly.20230828...v28.0.0-nightly.20230831

Repro: PWDEBUGIMPL=1 npm run etest electron/electron-app.spec.ts:22:5 with:

diff --git a/package.json b/package.json
index d489bedaa..aa41f0434 100644
--- a/package.json
+++ b/package.json
@@ -82,6 +82,7 @@
     "cross-env": "^7.0.3",
     "dotenv": "^16.0.0",
     "electron": "19.0.11",
+    "electron-nightly": "^29.0.0-nightly.20231115",
     "electron-to-chromium": "^1.4.212",
     "enquirer": "^2.3.6",
     "esbuild": "^0.18.11",
diff --git a/packages/playwright-core/src/server/electron/electron.ts b/packages/playwright-core/src/server/electron/electron.ts
index eeb27552a..3a4849036 100644
--- a/packages/playwright-core/src/server/electron/electron.ts
+++ b/packages/playwright-core/src/server/electron/electron.ts
@@ -150,7 +150,7 @@ export class Electron extends SdkObject {
         try {
           // By default we fallback to the Electron App executable path.
           // 'electron/index.js' resolves to the actual Electron App.
-          command = require('electron/index.js');
+          command = require('electron-nightly/index.js');
         } catch (error: any) {
           if ((error as NodeJS.ErrnoException)?.code === 'MODULE_NOT_FOUND') {
             throw new Error('\n' + wrapInASCIIBox([

@dgozman
Copy link
Contributor

dgozman commented Nov 9, 2023

From the bisect range, electron/electron#37535 looks most likely.

@mxschmitt
Copy link
Member

Turns out

console.log(process.mainModule)

or

console.log(require.main)

is undefined after this version. And we need this in order get access to the electron object inside our code as per

const source = `process.mainModule.require('electron')`;

mxschmitt added a commit that referenced this issue Dec 5, 2023
mstykow added a commit to opossum-tool/OpossumUI that referenced this issue Dec 6, 2023
- downgrade electron until Playwright issue is fixed: microsoft/playwright#28048

Signed-off-by: Maxim Stykow <maxim.stykow@tngtech.com>
julienmalard added a commit to reseau-constellation/iug that referenced this issue Dec 8, 2023
meretp pushed a commit to opossum-tool/OpossumUI that referenced this issue Dec 15, 2023
- downgrade electron until Playwright issue is fixed: microsoft/playwright#28048

Signed-off-by: Maxim Stykow <maxim.stykow@tngtech.com>
c3er added a commit to c3er/mdview that referenced this issue Dec 17, 2023
Electron 27 is still used, because Electron 28 doesn't work well with
Playwright yet. See Playwright issue #28048
microsoft/playwright#28048

markdown-it-emoji did a breaking change which makes it necessary to
change the "require" call.

Formatting via Prettier was changed slightly, which caused a change in
the "aboutDialog" module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants