question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot import @sentry/electron/main as library for main process

See original GitHub issue

Versions + Platform

  • [3.0.7] SDK version - @sentry/electron@v3.0.7
  • [17.2.0] Electron version - electron@v17.2.0
  • [MacOS] Platform - Windows/macOS/Linux

Description

Dear Sentry team,

Currently, when I try to use latest version 3.0.7 and use it for my project, I faced this error below:

image

And here is my implementation:

import { processTypes } from '../constants';
import isDevEnvironment from './applicationEnvironment';

// eslint-disable-next-line import/no-mutable-exports
let Sentry;

if (process.type === processTypes.renderer) {
  Sentry = require('@sentry/electron/renderer');
} else {
  Sentry = require('@sentry/electron/main');
}

if (!isDevEnvironment) {
  Sentry.init({
    debug: isDevEnvironment,
    dsn: 'DSN_LINK',
    onFatalError: error => {
      // Global uncaught errors will be sent to sentry and then the application will exit
      console.log('Fatal', error); // eslint-disable-line no-console
      process.exit(1);
    },
  });
}

export { Sentry as default };

May I ask for some help with it?

Many thanks ~

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
timfishcommented, Apr 26, 2022

You are getting the same error because you are still selecting the main/renderer SDK entry point at runtime.

Whenever you check process.type this is runtime detection. Your bundler doesn’t know what value to expect and subsequently includes both code paths in the bundle.

You need to remove index.js completely and call main/renderer from the earliest point in each process.

You could use the browser/node SDKs but you’d still have similar issues with bundler + runtime detection and you’d lose all the additional features the Electron SDK adds including:

  • Native crash reporting
  • Additional context and breadcrumbs
  • Merging of scope and context from multiple processes
0reactions
mx51damoncommented, Apr 27, 2022

Hi @timfish, I am not 100% sure I fixed my issue or not, but when I put sentry configuration file as part of entry configuration in webpack, the error is gone …

 entry: [
    IS_DEV && 'webpack/hot/poll?1000',
    IS_DEV && 'source-map-support/register',
    IS_DEV && './build/electron.js',
    './src/main/sentry.js',
    './src/main/index.js',
  ].filter(Boolean),

Something like this. Thanks for help mate 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Question - ERROR: cannot import the library '_pygimli_'. #140
I properly installed Anaconda ans msys command shell. Then I followed the "Building pyGIMLI from source" procedure. The following message error ...
Read more >
Cannot import shared library with g++ - c++ - Stack Overflow
i made a shared library, linked it to a main program, but this main program cannot see any of the shared library methods,...
Read more >
Electron | Sentry Documentation
@sentry/electron is the official Sentry SDK for Electron applications. It can capture JavaScript exceptions in the main and renderer processes, as well as ......
Read more >
Importing Existing Libraries to Your Connected Workspace in ...
The interface to this process – the Library Importer – presents a one-click solution ... select File » Library Importer from the main...
Read more >
Imported Libraries Overview - ADM Help Centers
Business Process Testing: After importing a library, do not change the content of either the existing source library from which a baseline is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found