question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MultiCompiler (array of webpack configs) causes "Cannot read property 'tap' of undefined" in WebpackDevServerUtils.js at `npm start`

See original GitHub issue

Describe the bug

After turning my webpack into a MultiCompiler (returning an array of configs instead of a single object to webpack), npm start would fail with a Cannot read property 'tap' of undefined error.

Did you try recovering your dependencies?

yes, did not help

Which terms did you search for in User Guide?

“npm start error” “tap undefined”. Did not find anything relevant.

Environment

npx: installed 98 in 7.446s

Environment Info:

  current version of create-react-app: 3.4.1
  running from <homedir>/.npm/_npx/59886/lib/node_modules/create-react-app

  System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  Binaries:
    Node: 14.4.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.8 - /usr/local/bin/npm
  Browsers:
    Chrome: 85.0.4183.121
    Firefox: 76.0.1
    Safari: 14.0
  npmPackages:
    react: ^16.9.0 => 16.13.1 
    react-dom: ^16.9.0 => 16.13.1 
    react-scripts: Not Found
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

  1. generate an array-of-configs in webpack.config.js (i.e. a MultiCompiler) based on the create-react-app config, with typescript enabled
  2. npm start

Expected behavior

devserver should start without error

Actual behavior

On npm start, the following error appears.

> cmp@0.1.0 start <app path>
> node scripts/start.js

Cannot read property 'tap' of undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cmp@0.1.0 start: `node scripts/start.js`
npm ERR! Exit status 1

Debugging with node --inspect-brk ./scripts/start.js indicates the problem is at https://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/WebpackDevServerUtils.js#L143

    compiler.hooks.beforeCompile.tap('beforeCompile', () => {

because MultiCompiler does not have a beforeCompile in hooks, it only has done, invalid, run, watchClose, watchRun, and infrastructureLog in hooks.

I fixed it with the following patch, but it seems incomplete, as it doesn’t handle the hooks.failed in isSmokeTest below (wasn’t quite sure if I should hook all the compilers, or just the last one). It also hangs with the message Files successfully emitted, waiting for typecheck results... after running npm start, but the devserver seems to work anyways.

--- node_modules/react-dev-utils/WebpackDevServerUtils.js	1985-10-26 01:15:00.000000000 -0700
+++ patches/WebpackDevServerUtils.js	2020-09-22 11:22:48.000000000 -0700
@@ -138,8 +138,11 @@
   let tsMessagesPromise;
   let tsMessagesResolver;
 
+  var isMulti = compiler.compilers && compiler.compilers.length > 0;
+  var firstCompiler = isMulti ? compiler.compilers[0] : compiler;
+
   if (useTypeScript) {
-    compiler.hooks.beforeCompile.tap('beforeCompile', () => {
+    firstCompiler.hooks.beforeCompile.tap('beforeCompile', () => {
       tsMessagesPromise = new Promise(resolve => {
         tsMessagesResolver = msgs => resolve(msgs);
       });

Reproducible demo

(working on a minimal repro)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:5

github_iconTop GitHub Comments

1reaction
as-zlynn-philippscommented, Apr 1, 2021

Solution for me was to set FAST_REFRESH=false in .env file. There goes 3 hours I’ll never get back.

0reactions
michaeltomasikcommented, Feb 16, 2022

Hey, any update on this one?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React- Webpack: Cannot read property 'tap' of undefined
... webpack config files for development and production, When I run "npm run start", it gives me error that: Cannot read property 'tap'...
Read more >
Node Interface - webpack
The MultiCompiler module allows webpack to run multiple configurations in separate compilers. If the options parameter in the webpack's NodeJS api is an...
Read more >
ts-loader - npm
Start using ts-loader in your project by running `npm i ... Second, you need to set the devtool option in your webpack.config.js to...
Read more >
webpack/webpack - Gitter
「wdm」: TypeError: Cannot read property 'tapAsync' of undefined at compiler.hooks.emit.tap (****/webpack-dev-middleware/lib/fs.js:18:37) at _next3 (eval at ...
Read more >
Serverless Webpack - Serverless Framework: Plugins
This allows to set properties in the webpack configuration differently depending if the lambda code is run on the local machine or deployed....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found