enhanced-resolve: Error when using webpack in watch mode

I have updated to the latest release of this library (3.4.0), and that caused the watch script I’ve added to package.json (actually it is just webpack -d -w) to break. It breaks with this error message:

/Users/daniel.rotter/Development/massiveart/sulu-minimal/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:145
			if(key.startsWith(what))
			      ^

TypeError: Cannot read property 'startsWith' of undefined
    at Storage.purge (/Users/daniel.rotter/Development/massiveart/sulu-minimal/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:145:10)
    at Storage.purge (/Users/daniel.rotter/Development/massiveart/sulu-minimal/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:150:9)
    at CachedInputFileSystem.purge (/Users/daniel.rotter/Development/massiveart/sulu-minimal/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:259:20)
    at Watchpack.watcher.once (/Users/daniel.rotter/Development/massiveart/sulu-minimal/node_modules/webpack/lib/node/NodeWatchFileSystem.js:42:26)
    at Object.onceWrapper (events.js:318:30)
    at emitTwo (events.js:125:13)
    at Watchpack.emit (events.js:213:7)
    at Watchpack._onTimeout (/Users/daniel.rotter/Development/massiveart/sulu-minimal/node_modules/watchpack/lib/watchpack.js:142:7)
    at ontimeout (timers.js:488:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:283:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ watch: `webpack -d -w`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

The initial build works, but this error occurs after I save a file being watched. Is there some compatability issue with this release?

If I downgrade to version 3.3.0 of this library the watch task is working again.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 46
  • Comments: 29

Commits related to this issue

Most upvoted comments

Looks like we have an undefined key here, likely from commit 03ef8f2:

		for(var key of this.data.keys()) {
			if(key.startsWith(what))
				this.data.delete(key);
		}

In a rush so I had to edit it like below as a temporary workaround:

		for(var key of this.data.keys()) {
			if (typeof key !== "string") {
				continue;
			}
			if(key.startsWith(what))
				this.data.delete(key);
		}

Hope this can be fixed soon.

Downgrading worked for me. If you’re using Yarn, think about updating your yarn.lock file when you install 3.3.0 manually :

enhanced-resolve@^3.3.0:
  version "3.3.0"
  resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.3.0.tgz#950964ecc7f0332a42321b673b38dc8ff15535b3"
  dependencies:
    graceful-fs "^4.1.2"
    memory-fs "^0.4.0"
    object-assign "^4.0.1"
    tapable "^0.2.5"