diff --git a/package.json b/package.json index 7279536..a745764 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "node": ">= 8" }, "dependencies": { - "@sentry/cli": "^1.74.4" + "@sentry/cli": "^1.74.4", + "webpack-sources": "^2.0.0 || ^3.0.0" }, "devDependencies": { "@types/webpack": "^4.41.31 || ^5.0.0", diff --git a/src/index.js b/src/index.js index 67cc9c8..abd0123 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ const SentryCli = require('@sentry/cli'); const path = require('path'); const util = require('util'); +const { RawSource } = require('webpack-sources'); const SENTRY_LOADER = path.resolve(__dirname, 'sentry.loader.js'); const SENTRY_MODULE = path.resolve(__dirname, 'sentry-webpack.module.js'); @@ -75,23 +76,11 @@ function attachAfterEmitHook(compiler, callback) { } function attachAfterCodeGenerationHook(compiler, options) { + // This is only a problem for folks on webpack 3 and below if (!compiler.hooks || !compiler.hooks.make) { return; } - let webpackSources; - try { - // eslint-disable-next-line global-require, import/no-extraneous-dependencies - webpackSources = require('webpack-sources'); - } catch (_e) { - // eslint-disable-next-line no-console - console.warn( - 'Coud not resolve package: webpack-sources. Skipping injection for the remote entry file.' - ); - return; - } - - const { RawSource } = webpackSources; const moduleFederationPlugin = compiler.options && compiler.options.plugins && diff --git a/yarn.lock b/yarn.lock index d406d03..76a90c5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4616,6 +4616,11 @@ webidl-conversions@^4.0.2: resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad" integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg== +"webpack-sources@^2.0.0 || ^3.0.0": + version "3.2.3" + resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" + integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== + webpack-sources@^3.2.0: version "3.2.1" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.1.tgz#251a7d9720d75ada1469ca07dbb62f3641a05b6d"