Skip to content

Commit 5816a41

Browse files
author
Luca Forstner
committed
fix(core): Use createRequire to not use built-in require in ESM
1 parent b328181 commit 5816a41

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

packages/bundler-plugin-core/rollup.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const extensions = [".js", ".ts"];
1313
export default {
1414
input,
1515
external: [...Object.keys(packageJson.dependencies), ...modulePackage.builtinModules],
16+
onwarn: (warning) => {
17+
throw new Error(warning.message); // Warnings are usually high-consequence for us so let's throw to catch them
18+
},
1619
plugins: [
1720
resolve({ extensions, preferBuiltins: true }),
1821
commonjs(),

packages/bundler-plugin-core/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { makeMain } from "@sentry/node";
2626
import os from "os";
2727
import path from "path";
2828
import fs from "fs";
29+
import { createRequire } from "module";
2930
import { promisify } from "util";
3031
import { getDependencies, getPackageJson, parseMajorVersion, stringToUUID } from "./utils";
3132
import { glob } from "glob";
@@ -35,6 +36,9 @@ import type { sources } from "webpack";
3536

3637
const ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".mjs"];
3738

39+
// Use createRequire because esm doesn't like built-in require.resolve
40+
const require = createRequire(import.meta.url);
41+
3842
const releaseInjectionFilePath = require.resolve(
3943
"@sentry/bundler-plugin-core/sentry-release-injection-file"
4044
);

packages/bundler-plugin-core/src/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"resolveJsonModule": true, // needed to import package.json
88
"types": ["node"],
99
"target": "ES6", // needed for some iterator features
10+
"module": "es2020",
1011
"lib": ["ES2020", "DOM"] // es2020 needed for "new Set()", DOM needed for various bundler types
1112
}
1213
}

0 commit comments

Comments
 (0)