forge icon indicating copy to clipboard operation
forge copied to clipboard

Unable to import module in main process

Open mmarczell-graphisoft opened this issue 3 months ago • 2 comments

Pre-flight checklist

  • [x] I have read the contribution documentation for this project.
  • [x] I agree to follow the code of conduct that this project uses.
  • [x] I have searched the issue tracker for a bug that matches the one I want to file, without success.

Forge version

7.9.0

Electron version

37.2.0

Operating system

macOS 26

Last known working Forge version

No response

Expected behavior

The Electron window appears and displays "Hello world"

Actual behavior

An error message appears:

Uncaught Exception:
Error: Cannot find module '@opentelemetry/instrumentation'
Require stack:
- /Volumes/SSD/Dev/Sandbox/forgebug/out/forgebug-darwin-arm64/forgebug.app/Contents/Resources/app.asar/node_modules/@sentry/node-core/build/cjs/otel/instrument.js
- /Volumes/SSD/Dev/Sandbox/forgebug/out/forgebug-darwin-arm64/forgebug.app/Contents/Resources/app.asar/node_modules/@sentry/node-core/build/cjs/integrations/http/index.js
- /Volumes/SSD/Dev/Sandbox/forgebug/out/forgebug-darwin-arm64/forgebug.app/Contents/Resources/app.asar/node_modules/@sentry/node-core/build/cjs/index.js
- /Volumes/SSD/Dev/Sandbox/forgebug/out/forgebug-darwin-arm64/forgebug.app/Contents/Resources/app.asar/node_modules/@sentry/node/build/cjs/integrations/http.js
- /Volumes/SSD/Dev/Sandbox/forgebug/out/forgebug-darwin-arm64/forgebug.app/Contents/Resources/app.asar/node_modules/@sentry/node/build/cjs/index.js
- /Volumes/SSD/Dev/Sandbox/forgebug/out/forgebug-darwin-arm64/forgebug.app/Contents/Resources/app.asar/node_modules/@sentry/electron/main/index.js
- /Volumes/SSD/Dev/Sandbox/forgebug/out/forgebug-darwin-arm64/forgebug.app/Contents/Resources/app.asar/dist/main.js
- 
at Module._resolveFilename (node:internal/modules/cjs/loader:1408:15)
at s._resolveFilename (node:electron/js2c/browser_init:2:129632)
at defaultResolveImpl (node:internal/modules/cjs/loader:1064:19)
at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1069:22)
at Module._load (node:internal/modules/cjs/loader:1218:37)
at c._load (node:electron/js2c/node_init:2:18013)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:242:24)
at Module.require (node:internal/modules/cjs/loader:1494:12)
at require (node:internal/modules/helpers:135:16)

Steps to reproduce

  1. Check out the following repository: https://github.com/mmarczell-graphisoft/forgebug
  2. npm install
  3. npx gulp buildMac (or buildWin)
  4. open ./out/forgebug-darwin-arm64/forgebug.app (or \out\forgebug-darwin-arm64\forgebug.exe)

Additional information

It seems the algorithm that electron-forge uses to determine which node_modules get included in app.asar does not work well in this case. If I unpack the asar, the node_modules/@opentelemetry/instrumentation folder does not exist in it.

mmarczell-graphisoft avatar Oct 07 '25 12:10 mmarczell-graphisoft

Some additional information to provide a better overview of the specific issue. The only difference between this app and a blank Electron template is two twings:

  1. The main process code is built with tsc
  2. There is a dependency on @sentry/electron which is invoked in the main process.

mmarczell-graphisoft avatar Oct 07 '25 13:10 mmarczell-graphisoft

Currently using @sentry/electron in some of the Forge apps I maintain, but I think we might be a few major versions behind. Let me upgrade and see if I can repro as well. 🤔

erickzhao avatar Oct 07 '25 17:10 erickzhao