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

Cannot find module 'node: assert' Require stack #43

Open
chaklasiyanikunj opened this issue Nov 24, 2022 · 10 comments
Open

Cannot find module 'node: assert' Require stack #43

chaklasiyanikunj opened this issue Nov 24, 2022 · 10 comments

Comments

@chaklasiyanikunj
Copy link

chaklasiyanikunj commented Nov 24, 2022

I installed win32-API version => "win32-api": "^20.1.0".
My Node version is 14.18.5.

The Notepad file is open on my PC.

Screenshot 2022-11-24 163247

try {
          console.log("Preload -- Try part called")
          const Win32 = require('win32-api/promise');
          const User32 = Win32.User32.load(['FindWindowExW', 'SetWindowPos']);
          var className = "Notepad"
          const SWP_NOMOVE = 0x0002, SWP_NOACTIVATE = 0x0010;
 
          module.exports = {
               ResizeWindow: async function ResizeWindow(className) {
                    const lpszClass = Buffer.from(className + '\0', 'ucs2')
                    const hWnd = await User32.FindWindowExW(0, 0, lpszClass, null); 
                    User32.SetWindowPos(hWnd, 0, 0, 0, 600, 600, SWP_NOMOVE | SWP_NOACTIVATE); 
               }
          };
} catch(e){
       console.log("Preload -- Catch part called")
       console.log("Exception ::",e)
}

Screenshot 2022-11-24 162636

When trying this code in electron it gives this => "Cannot find module 'node: assert' Require stack" error.

Screenshot 2022-11-24 162702

I've tried to find the solution. but haven't found anything yet.
Anyone any idea about this?

@waitingsong
Copy link
Owner

waitingsong commented Nov 24, 2022

Node v14 not support syntax import * from 'node:assert' , only import * from 'assert' without node: prefix
Try upgrade the version to v16?

@chaklasiyanikunj
Copy link
Author

chaklasiyanikunj commented Nov 24, 2022

Thank you for your reply. I already tried with Node versions: 16.17.0 and 16.17.1. But received the same error. I wrote only the above code. Do we need to require any other statement?

@waitingsong
Copy link
Owner

whats the version of electron?

@chaklasiyanikunj
Copy link
Author

I used the below electron version :

"electron": "^11.3.0",
"electron-local-crash-reporter": "^1.0.2",
"electron-progressbar": "^2.0.0",
"electron-updater": "^4.3.9",

@waitingsong
Copy link
Owner

waitingsong commented Nov 24, 2022

The version of nodejs may under v14 some where.
You can try a simple file:

const assert = requrire('node:assert')
console.log(assert)

or

import * as assert from 'node:assert'
console.log(assert)

v14 also suppports
https://nodejs.org/api/esm.html#node-imports

@chaklasiyanikunj
Copy link
Author

I tried both statements. Still, I am getting this error. Do we need to add this npm package to Electron App?

@waitingsong
Copy link
Owner

waitingsong commented Nov 25, 2022

I think https://www.npmjs.com/package/assert is unnecessary, it's not nodejs inernal module ( import by prfix node:) .
provide a simple repo for debug ?

@chaklasiyanikunj
Copy link
Author

Sample Repo is available here and I added a Readme.txt file for more details.
Electron_Sample_App.zip

@waitingsong
Copy link
Owner

electron v11 bundled with nodejs v12 : https://www.electronjs.org/blog/electron-11-0
electron v12 bundled with nodejs v14, pls try

@Jugbot
Copy link

Jugbot commented Dec 1, 2022

I found that you need to add this to your BrowserWindow:

    webPreferences: {
      sandbox: false,
      //nodeIntegration: true, // Or this
    }

Otherwise node libraries wont be available. Note that this is done for security reasons.

Tangential note (unrelated to the above issue) electronV21+ wont work due to https://www.electronjs.org/blog/v8-memory-cage

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

No branches or pull requests

3 participants