Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webpack): explicitly pass outputFileSystem to webpackDevMiddleware #7613

Merged
merged 1 commit into from Jun 26, 2020

Conversation

simplesmiler
Copy link

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

I got hit by nuxt/typescript#145 a couple of days ago, and together with @crutch12 we were able to determine the reason.

It is not triggered in particular by lerna, @nuxt/typescript, and can also be reproduced with yarn.

The culprit happens to be in the interaction between @nuxt/webpack, webpack-dev-middleware and memory-fs, and how the package manager (e.g. npm or yarn) decides to dedupe them on disk.

In particular, webpack-dev-middleware@3.7.2 performs a check compiler.outputFileSystem instanceof MemoryFileSystem: https://github.com/webpack/webpack-dev-middleware/blob/v3.7.2/lib/fs.js#L112

  1. When @nuxt/webpack and webpack-dev-middleware happen to "share" the deduped memory-fs (i.e. it is hoisted to a top of node_modules), then the check passes, and everything is snazzy.
  2. When memory-fs happens to be "inlined" (i.e. another version of memory-fs is hoisted to the top of node_modules), then the check fails, and webpack-dev-middleware creates it's own instance of MemoryFileSystem to write to, and the original AsyncMFS created by @nuxt/webpack never gets populated with compiled files.

Reproduction is quite easy, you just have to have top level memory-fs dependency of a different version than the one used by @nuxt/webpack and webpack-dev-middleware:

# Start from empty folder
npm i nuxt@2.13.1 memory-fs@0.5.0
npx nuxt
# Open browser and see the error

A solution we were able to find is to explicitly pass file system instance through webpack-dev-middleware options instead of relying on it to extract the file system instance from the compiler instance.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@codecov-commenter
Copy link

Codecov Report

Merging #7613 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev    #7613   +/-   ##
=======================================
  Coverage   70.28%   70.28%           
=======================================
  Files          88       88           
  Lines        3749     3749           
  Branches     1020     1020           
=======================================
  Hits         2635     2635           
  Misses        905      905           
  Partials      209      209           
Flag Coverage Δ
#unittests 70.28% <ø> (ø)
Impacted Files Coverage Δ
packages/webpack/src/builder.js 13.33% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b070e19...f369c19. Read the comment docs.

@Atinux Atinux requested a review from pi0 June 26, 2020 12:52
@pi0 pi0 changed the title Fix memory-fs confusion fix(webpack): fix memory-fs confusion Jun 26, 2020
@pi0 pi0 changed the title fix(webpack): fix memory-fs confusion fix(webpack): explicitly pass outputFileSystem to webpackDevMiddleware Jun 26, 2020
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM. We have same fix for next (webpack5) branch :)

@pi0 pi0 merged commit a87218b into nuxt:dev Jun 26, 2020
@pi0 pi0 mentioned this pull request Jun 26, 2020
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants