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.

3.0.0 Webpack "Self-reference dependency has unused export name: This should not happen"

See original GitHub issue

Hi there! I’m really excited to see the 3.0 release bringing release health metrics, thanks for adding that.

This morning I attempted to migrate to version 3.0 using https://github.com/getsentry/sentry-electron/blob/3.0.0/MIGRATION.md#. It all works in development Webpack builds, but when using Webpack to make a production build mode: 'production' of my app, I receive the following errors:

ERROR in ./node_modules/@sentry/electron/preload/index.js
Self-reference dependency has unused export name: This should not happen
Error: Self-reference dependency has unused export name: This should not happen
    at CommonJsSelfReferenceDependencyTemplate.apply (/Users/vagrant/git/node_modules/webpack/lib/dependencies/CommonJsSelfReferenceDependency.js:102:10)
    at JavascriptGenerator.sourceDependency (/Users/vagrant/git/node_modules/webpack/lib/javascript/JavascriptGenerator.js:206:12)
    at JavascriptGenerator.sourceModule (/Users/vagrant/git/node_modules/webpack/lib/javascript/JavascriptGenerator.js:112:9)
    at JavascriptGenerator.generate (/Users/vagrant/git/node_modules/webpack/lib/javascript/JavascriptGenerator.js:98:8)
    at NormalModule.codeGeneration (/Users/vagrant/git/node_modules/webpack/lib/NormalModule.js:1198:22)
    at /Users/vagrant/git/node_modules/webpack/lib/Compilation.js:3324:22
    at /Users/vagrant/git/node_modules/webpack/lib/Cache.js:93:5
    at Hook.eval [as callAsync] (eval at create (/Users/vagrant/git/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Cache.get (/Users/vagrant/git/node_modules/webpack/lib/Cache.js:75:18)
    at ItemCacheFacade.get (/Users/vagrant/git/node_modules/webpack/lib/CacheFacade.js:111:15)
 @ ./node_modules/@sentry/electron/main/integrations/preload-injection.js 40:18-59
 @ ./node_modules/@sentry/electron/main/integrations/index.js 13:26-56
 @ ./node_modules/@sentry/electron/main/index.js 6:33-58
 @ ./src/app/crash-reporter/crash-reporter.js 281:85-117
 @ ./src/js/index.tsx 15:0-76 31:2-25

ERROR in ./node_modules/@sentry/electron/preload/legacy.js
Self-reference dependency has unused export name: This should not happen
Error: Self-reference dependency has unused export name: This should not happen
    at CommonJsSelfReferenceDependencyTemplate.apply (/Users/vagrant/git/node_modules/webpack/lib/dependencies/CommonJsSelfReferenceDependency.js:102:10)
    at JavascriptGenerator.sourceDependency (/Users/vagrant/git/node_modules/webpack/lib/javascript/JavascriptGenerator.js:206:12)
    at JavascriptGenerator.sourceModule (/Users/vagrant/git/node_modules/webpack/lib/javascript/JavascriptGenerator.js:112:9)
    at JavascriptGenerator.generate (/Users/vagrant/git/node_modules/webpack/lib/javascript/JavascriptGenerator.js:98:8)
    at NormalModule.codeGeneration (/Users/vagrant/git/node_modules/webpack/lib/NormalModule.js:1198:22)
    at /Users/vagrant/git/node_modules/webpack/lib/Compilation.js:3324:22
    at /Users/vagrant/git/node_modules/webpack/lib/Cache.js:93:5
    at Hook.eval [as callAsync] (eval at create (/Users/vagrant/git/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Cache.get (/Users/vagrant/git/node_modules/webpack/lib/Cache.js:75:18)
    at ItemCacheFacade.get (/Users/vagrant/git/node_modules/webpack/lib/CacheFacade.js:111:15)
 @ ./node_modules/@sentry/electron/main/integrations/preload-injection.js 39:18-60
 @ ./node_modules/@sentry/electron/main/integrations/index.js 13:26-56
 @ ./node_modules/@sentry/electron/main/index.js 6:33-58
 @ ./src/app/crash-reporter/crash-reporter.js 281:85-117
 @ ./src/js/index.tsx 15:0-76 31:2-25

My crash reporter code is mostly unchanged from 2.x implementation (I was using 2.5.4 before). I have a single crash-reporter.js file that the renderer and main process share. Here is the basic structure of that file:

module.exports.initializeCrashReporter = function () {
    Sentry().init({
      dsn: '__DSN__',
      release: '__VERSION__'
    });
};

// This has to be dynamically loaded because it's different between the main and renderer processes
// https://github.com/getsentry/sentry-electron/blob/3.0.0/MIGRATION.md#relative-imports
function Sentry() {
  return isRendererProcess()
    ? require('@sentry/electron/renderer')
    : require('@sentry/electron/main');
}

The only change I had to make to migrate to 3.x implementation was within the Sentry function, changing the require paths. Before, on 2.5.4, the code was return isRendererProcess() ? require('@sentry/electron/dist/renderer') : require('@sentry/electron/dist/main'); Note that the dist has been removed from the path for 3.x impl.

Any advice here on how to fix this? I should note that development Webpack builds work completely fine, but changing my webpack config to mode: 'production' causes the error. I am using Webpack version 5.69.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
quanglam2807commented, Mar 30, 2022
1reaction
adambailey-commented, Feb 17, 2022

Thanks, refactoring the code helps me work around the issue. Appreciate your time!

Read more comments on GitHub >

github_iconTop Results From Across the Web

`exports.nodeType`: Self-reference dependency has unused ...
Bug report Importing a library built by webpack 4 (amd) into webpack 5 project results in Self-reference dependency has unused export name ......
Read more >
Webpack including unused exports in final bundle (not tree ...
I believe when importing dependencies, it is better to import only the necessary function/component from the library and this will be packed ...
Read more >
Tree Shaking - webpack
The name and concept have been popularized by the ES2015 module bundler rollup. ... is what's known as "dead code", meaning an unused...
Read more >
has-package-self-reference - npm
This library exports true if the current node version supports it, false if it does not, and null if it's in a browser....
Read more >
find-unused-exports - npm Package Health Analysis - Snyk
A CLI and equivalent JS API to find unused ECMAScript module exports in a project. For more information about how to use this...
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