webpack.validateSchema is not a function

2019-01-16 23:24发布

问题:

Webpack are throwing this error all of a sudden:

TypeError: webpack.validateSchema is not a function

Everything was working fine Friday, not working today. No new commits to master since Friday.

Pruned NPM, that didn't work, deleted NPM folder and re-installed, no dice. Checked out to previous branches which have not been rebased from Master for over a week. Still the same.

Anyone have an idea?

回答1:

Looks like npm bug, since webpack-dev-server@2.1.0-beta.11 requires webpack@^2.1.0-beta.26 but npm failed to install it.

The easiest way to avoid the issue without updating too much is to change dependency in package.json to

  "webpack-dev-server": "2.1.0-beta.10",

Instead of something like

  "webpack-dev-server": "^2.1.0-beta.9",

"^" char before version says "compatible with". Removing it sticks to the version exactly.

Don't forget to run npm install or npm update afterwards.



回答2:

I ran into this problem today at virtually the same time as you, it turns out that webpack was updated again.

Here is what I did to fix it:

First I ran npm install and npm update to see what the result was. I ran both of these commands because npm has a weird way of reporting unmet dependancies, sometimes its wrong and when you re-run the npm update or the npm install, you will realize that the unmet dependencies are no longer an issue.

After I ran these commands I noticed that the only remaining message was a warning:

npm WARN webpack-dev-server@2.1.0-beta.11 requires a peer of webpack@^2.1.0-beta.26 but none was installed.

To get rid of this I changed my package.json file to read "webpack": "2.1.0-beta.26" instead of "webpack": "2.1.0-beta.25" and ran another npm install.

After this I got another error when I tried running npm start which stated that there was a problem with my webpack config file. In my case, I went to the webpack config file for my development environment (because I am not on production yet) and I found the culprit which was an invalid parameter called 'outputPath'.

I commented out that line and now I get everything working fine.

Hope this helps, may just be a hack for now but hopefully it is a step in the right direction.

UPDATE:

Ok, so I was a bit wrong about everything 'working fine'. It turns out that some of my loaders were not working correctly; Bootstrap and some other things were not being loaded in properly, breaking my styles. So, to get it back to where I was before, I deleted my node_modules folder and ran npm install using the following in package.json:

"webpack": "2.1.0-beta.25",
"webpack-dashboard": "^0.1.8",
"webpack-dev-middleware": "^1.6.1",
"webpack-dev-server": "2.1.0-beta.9",
"webpack-md5-hash": "^0.0.5",
"webpack-merge": "^0.15.0",

Hopefully discussions like this one will help us figure out how to move forward properly with the new versions of webpack being released.



回答3:

I got the same error as well. I locked my version of webpack-dev-server in my package.json file and that prevented the error from occurring. That doesn't fix the root problem of the bug though.

This is the version of webpack-dev-server that I'm using but I'm sure later versions work as well: "webpack-dev-server": "2.1.0-beta.9",



回答4:

it worked for me when i delete ^ and use the exact version.

From

"webpack": "2.1.0-beta.25",
"webpack-dev-middleware": "^1.6.1",
"webpack-dev-server": "^2.1.0-beta.9",
"webpack-md5-hash": "^0.0.5",
"webpack-merge": "^0.14.1"

to

"webpack": "2.1.0-beta.25",
"webpack-dev-middleware": "1.6.1",
"webpack-dev-server": "2.1.0-beta.9",
"webpack-md5-hash": "0.0.5",
"webpack-merge": "0.14.1"


回答5:

It worked for me when i did:

Uninstall following package:

npm uninstall webpack webpack-dev-server --save -dev

Install following Packages:

npm install --save -dev webpack@3.10.0

npm install --save -dev webpack-cli@2.0.10

npm install --save -dev webpack-dev-server@2.9.7



回答6:

Alright, update here.

Tried what a few of you guys suggested, which unfortunately just got me deeper into a rabbit hole of errors with broken module loaders.

In the end, I updated to "webpack": "^2.1.0-beta.26", and "webpack-dev-server": "^2.1.0-beta.11". After that, found out there were breaking changes, causing the loaders to break - https://github.com/webpack/webpack/releases.

in short, in your webpack config, change loaders: [ ... ], to rules : [ ... ], and on all loader declarations, append "-loader" to the string value as this, { test: /node_modules\/i18n-iso-countries\/(de|es|nl|sv)\.js$/, loader: 'null-loader' }, { test: /\.coffee$/, loader: 'coffee-loader' }, { test: /\.ts$/, loader: ['awesome-typescript-loader']} etc.

Did it for me. Hope this helps anyone else running into the issue.



回答7:

I got it working by running this command:

npm install --save-dev webpack-dev-server@beta webpack@beta


回答8:

As explained in this GitHub issue, you need to update webpack to webpack 2.1.0-beta.26 or later. Since the last v2.1 release is beta.28, you should require webpack@^2.1.0-beta.28.

Note that one of the breaking changes introduced in beta.26 is that you need to specify the full name of loaders, e.g. replace loader: 'babel' with loader: 'babel-loader'.



回答9:

Got the same issue when we upgraded angular/cli to 1.6.3 and when we test the ng -v we get an error towards webpack. So we happen to uninstall webpack, do an cache clean and then installed the webpack again globally. It resolved the issue



回答10:

I got this problem because I had an older global version of webpack installed that was somehow conflicting with the project-specific webpack.

I first un-installed the global (older) webpack by running:

npm uninstall webpack -g

Then I ran my project-specific webpack. On windows webpack.cmd resides in node_modules.bin\, but if you run webpack via an npm task, npm will search the .bin folder automatically, so no need to specify that path explicitly.

The functioning npm run task in my package.json looks as follows:

  "scripts": {
      "webpack": "webpack -w --config ./config/dev.js --progress"
  }