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

TypeError: Cannot read property 'invalid' of undefined #295

Closed
1 task
qingyulove opened this issue Apr 9, 2018 · 4 comments
Closed
1 task

TypeError: Cannot read property 'invalid' of undefined #295

qingyulove opened this issue Apr 9, 2018 · 4 comments

Comments

@qingyulove
Copy link

  • Operating System: windows 10
  • Node Version: v8.11.1
  • NPM Version: v5.8.0
  • webpack version: 3.6.0
  • webpack-dev-middleware Version: 3.1.2
  • This is a bug

Code

require('./check-versions')()

var config = require('../config')
if (!process.env.NODE_ENV) {
  process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
}

var opn = require('opn')
var path = require('path')
var express = require('express')
var webpack = require('webpack')
var proxyMiddleware = require('http-proxy-middleware')
var webpackConfig = require('./webpack.dev.conf')

// default port where dev server listens for incoming traffic
var port = process.env.PORT || config.dev.port
// automatically open browser, if not set will be false
var autoOpenBrowser = !!config.dev.autoOpenBrowser
// Define HTTP proxies to your custom API backend
// https://github.com/chimurai/http-proxy-middleware
var proxyTable = config.dev.proxyTable

var app = express()
var compiler = webpack(webpackConfig)

var devMiddleware = require('webpack-dev-middleware')(compiler, {
  publicPath: webpackConfig.output.publicPath,
  quiet: true,
  invalid: false,
})

var hotMiddleware = require('webpack-hot-middleware')(compiler, {
  log: () => {}
})
// force page reload when html-webpack-plugin template changes
compiler.plugin('compilation', function (compilation) {
  compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
    hotMiddleware.publish({ action: 'reload' })
    cb()
  })
})

// proxy api requests
Object.keys(proxyTable).forEach(function (context) {
  var options = proxyTable[context]
  if (typeof options === 'string') {
    options = { target: options }
  }
  app.use(proxyMiddleware(options.filter || context, options))
})

// handle fallback for HTML5 history API
app.use(require('connect-history-api-fallback')())

// serve webpack bundle output
app.use(devMiddleware)

// enable hot-reload and state-preserving
// compilation error display
app.use(hotMiddleware)

// serve pure static assets
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static'))

var uri = 'http://localhost:' + port

var _resolve
var readyPromise = new Promise(resolve => {
  _resolve = resolve
})

console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
  console.log('> Listening at ' + uri + '\n')
  // when env is testing, don't need open it
  if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
    opn(uri)
  }
  _resolve()
})

var server = app.listen(port)

module.exports = {
  ready: readyPromise,
  close: () => {
    server.close()
  }
}

For Bugs;

qq 20180409154539

@shellscape
Copy link
Contributor

webpack version: 3.6.0

webpack-dev-middleware 3.x.x requires webpack@4 or higher. Please read the release notes or see peerDependencies in package.json.

@Zammy
Copy link

Zammy commented Nov 24, 2019

I am using "webpack-dev-middleware": "^3.7.2" and "webpack": "^4.41.2" but I get this exception when trying to watch with webpack. I read what peerDependencies are in package.json but I do not completely understand what I am supposed to do. I added "peerDependencies": { "webpack": "^4.41.2" } to package.json and installed again. It did not fix the issue.
What am I doing wrong?

@bernardwang
Copy link

@Zammy I am also seeing the same issue, I've updated to the latest webpack-dev-middleware and webpack but I'm still seeing this error

@andrewphillipo
Copy link

Did anyone ever solve this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants