From e6444c0d4d157a3d526d1c9dfad083d64735e7f4 Mon Sep 17 00:00:00 2001 From: Endi Date: Tue, 29 Oct 2019 14:43:27 +0700 Subject: [PATCH] fix(v2): webpack modules resolve should prioritize @docusaurus/core own deps (#1907) * fix(v2): webpack modules resolve should prioritize own deps * nits --- CHANGELOG-2.x.md | 2 ++ packages/docusaurus/src/webpack/base.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG-2.x.md b/CHANGELOG-2.x.md index 188033449c..c387917698 100644 --- a/CHANGELOG-2.x.md +++ b/CHANGELOG-2.x.md @@ -9,6 +9,8 @@ - Refactor dark toggle into a hook. - Changed the way we read the `USE_SSH` env variable during deployment to be the same as in v1. - Fix accessing `docs/` or `/docs/xxxx` that does not match any existing doc page should return 404 (Not found) page, not blank page. +- Prioritize `@docusaurus/core` dependencies/ node_modules over user's node_modules. This fix a bug whereby if user has core-js@3 on its own node_modules but docusaurus depends on core-js@2, we previously encounter `Module not found: core-js/modules/xxxx` (because core-js@3 doesn't have that). +Another example is if user installed webpack@3 but docusaurus depends on webpack@4. - Added code block line highlighting feature (thanks @lex111)! If you have previously swizzled the `CodeBlock` theme component, it is recommended to update your source code to have this feature. ## 2.0.0-alpha.31 diff --git a/packages/docusaurus/src/webpack/base.ts b/packages/docusaurus/src/webpack/base.ts index bbbca0c383..ce6ea57a04 100644 --- a/packages/docusaurus/src/webpack/base.ts +++ b/packages/docusaurus/src/webpack/base.ts @@ -50,10 +50,13 @@ export function createBaseConfig( '@generated': generatedFilesDir, '@docusaurus': path.resolve(__dirname, '../client/exports'), }, - modules: [ - 'node_modules', + // This allows you to set a fallback for where Webpack should look for modules. + // We want `@docusaurus/core` own dependencies/`node_modules` to "win" if there is conflict + // Example: if there is core-js@3 in user's own node_modules, but core depends on + // core-js@2, we should use core-js@2. + modules: module.paths.concat([ path.resolve(fs.realpathSync(process.cwd()), 'node_modules'), - ], + ]), }, optimization: { removeAvailableModules: false,