Skip to content

Commit 2f93b1a

Browse files
committed
esbuild: graceful continue when bundling dead code
1 parent 0144fb3 commit 2f93b1a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/datadog-esbuild/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ module.exports.setup = function (build) {
3939

4040
if (args.namespace === 'file' && packagesOfInterest.has(packageName)) {
4141
// The file namespace is used when requiring files from disk in userland
42-
const pathToPackageJson = require.resolve(`${packageName}/package.json`, { paths: [ args.resolveDir ] })
42+
43+
let pathToPackageJson
44+
try {
45+
pathToPackageJson = require.resolve(`${packageName}/package.json`, { paths: [ args.resolveDir ] })
46+
} catch (err) {
47+
if (err.code === 'MODULE_NOT_FOUND') {
48+
console.warn(`Unable to open "${packageName}/package.json". Is the "${packageName}" package dead code?`)
49+
return
50+
} else {
51+
throw err
52+
}
53+
}
54+
4355
const pkg = require(pathToPackageJson)
4456

4557
if (DEBUG) {

0 commit comments

Comments
 (0)