From 7fcae064b205ab30c2393c3ce68171fd9f47ffc1 Mon Sep 17 00:00:00 2001 From: Fathy Boundjadj Date: Wed, 20 Dec 2017 05:17:51 +0100 Subject: [PATCH] Resolve "module", "jsnext:main" and "browser" before "main" (#299) Fixes #298 --- src/Resolver.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Resolver.js b/src/Resolver.js index 963cddea5be..04079b45ad1 100644 --- a/src/Resolver.js +++ b/src/Resolver.js @@ -46,6 +46,16 @@ class Resolver { packageFilter(pkg, pkgfile) { // Expose the path to the package.json file pkg.pkgfile = pkgfile; + + // npm libraries can specify alternative main fields in their package.json, + // we resolve the "module" and "jsnext:main" in priority of "browser" to get the full dependency tree. + // libraries like d3.js specifies node.js specific files in the "main" which breaks the build + const main = pkg.module || pkg['jsnext:main'] || pkg.browser; + + if (main) { + pkg.main = main; + } + return pkg; } });