sentry-electron: I update to 0.5.4, error on MODULE_NOT_FOUND
I update @sentry/electron 0.4.1 to 0.5.4.
And I rewrite function create to init.
My src/sentry.js.
import { init, captureMessage } from '@sentry/electron';
init({ dsn: 'foobar' });
captureMessage('Hello, world!');
So sentry is failed. (My application name replaced to foo)
{ Error: Cannot find module "/home/ncaq/Desktop/foo/package.json".
at webpackEmptyContext (/home/ncaq/Desktop/foo/app/webpack:/node_modules/@sentry/electron/dist/main sync:2:1)
at getPackageJson (/home/ncaq/Desktop/foo/app/webpack:/node_modules/@sentry/electron/dist/main/context.js:80:1)
at /home/ncaq/Desktop/foo/app/webpack:/node_modules/@sentry/electron/dist/main/context.js:240:25
at Generator.next (<anonymous>)
at fulfilled (/home/ncaq/Desktop/foo/app/webpack:/node_modules/@sentry/electron/dist/main/context.js:4:42)
at <anonymous> code: 'MODULE_NOT_FOUND' }
However, /home/ncaq/Desktop/foo/package.json exist.
Since this is a full path, it is hard to think that searching for webpack or babel is the cause.
Is it bug? Or my setting is invalid?
My env.
- babel: 7.0.0-beta.46
@sentry/electron: 0.5.4- react: 16.2.0
- webpack: 4.6.0
- electron: 1.8.4
- OS: Gentoo Linux
- node: v9.10.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 27 (12 by maintainers)
@maplemike Thanks so much. I landed on something similar. What worked for me with a project based on electron-react-boilerplate and Electron 1.7.14.
Use app/package.json in the two-package.json scheme
Add @sentry/electron to app/package.json, not package.json. I think this makes sure that the package is in Webpack
externalsas directed by @jan-auer.In main process (app/main.dev.js)
In renderer process (app/index.js)
Script for uploading sourcemaps with sentry-cli
I gave up on using the Webpack plugin since that is confused by electron-react-boilerplate having 2 different Webpack setups (1 for main process, 1 for renderer process). Instead, I just use sentry-cli.
Add sentry-cli to devDependencies in top-level package.json
upload_sourcemaps.sh
In the top-level package.json
Change
yarn releasecommand:I also added this command so I could easily test by tweaking my env.production (I use dotenv to manage environmental variables)
With all this setup, running
yarn releaseto ship a new version of the app uploads the sourcemaps to Sentry as a release calledmyapp-production-1.1.0before uploading the fully built macOS package to Amazon S3. The release is set similarly in the code. Errors are coming in with sourcemaps working. 👍Seems like electron-react-boilerplate is causing some confusion with their multiple package.jsons and configuration. I have to admit that I haven’t tried that boilerplate yet, but will give it a go and see whether we can make the integration process easier. Thanks for all the feedback so far.
Having said that, we can probably not account for the seemingly complex way the boilerplate is structured. My goal is to get this SDK to work with webpack, and not this specific boilerplate.
Some general things:
@sentry/electronin both the main process and renderer javascripts in the exact same way. In the main process webpack configuration, it should be declared external. In renderer webpack configuration it should not be declared external (although it wouldn’t matter as long as you have node integration enabled).one small thing to add to @aguynamedben’s answer about the sourcemaps upload: following the document
add following snippet to your webpack.**.prod.js
it will upload for you when you make a release build
@aguynamedben This was a nightmare to get going…I’m a Python developer and have been using Sentry for years
webpack.config.base.js
What I did…
This resolved the module not found error, source maps were another issue…
Sourcemaps
Updating the latest version of the boilerplate should fix this, it was caused by the boilerplate producing bad sourcemaps
If that is too much:
Hope that helps…finally have it all working!