[英]Webpack (v 3.0.0) validateSchema error in dev mode
Yesterday I installed webpack-cli
, it worked well with react
and other packages, today I just want to set up my webpack config file again, but when I run webpack-dev-server through npm it just spits out this error: 昨天我安装了
webpack-cli
,它与react
和其他软件包配合得很好,今天我只想再次设置我的webpack配置文件,但是当我通过npm运行webpack-dev-server时它只是吐出这个错误:
K:\web\07_Webpack_Test\node_modules\webpack-cli\bin\convert-argv.js:7
const validateSchema = process.webpackModule.validateSchema;
^
TypeError: Cannot read property 'validateSchema' of undefined
at Object.<anonymous> (K:\web\07_Webpack_Test\node_modules\webpack-cli\bin\convert-argv.js:7:46)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (K:\web\07_Webpack_Test\node_modules\webpack-dev-server\bin\webpack-dev-server.js:234:15)
at Module._compile (internal/modules/cjs/loader.js:678:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! 07_webpack_test@1.0.0 dev: `webpack-dev-server -d`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the 07_webpack_test@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Eric PC\AppData\Roaming\npm-cache\_logs\2018-06-02T07_12_22_842Z-debug.log
Here is my command to run it : 这是我运行它的命令:
"scripts": {
"dev": "webpack-dev-server -d",
"build": "npm run clear && webpack -p",
"clear": "rimraf ./public/*"
},
Here is my webpack.config.js: 这是我的webpack.config.js:
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: {
app: './src/js/app.jsx',
},
output: {
path: path.resolve(__dirname , 'public'),
filename: '[name].bundle.js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /\.scss$/,
use : ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader' , 'sass-loader'],
publicPath: "/public"
})
}
]
},
resolve: {
extensions: ['.js', '.jsx']
},
plugins: [
new HtmlWebpackPlugin({
title: 'React App',
filename: 'index.html',
template: './src/index.html'
}),
new ExtractTextPlugin({
filename: 'app.css',
disable: false,
allChunks: true
})
],
devServer: {
contentBase: '/public',
compress: true,
port: 3000,
open: true,
historyApiFallback: true,
stats: 'errors-only'
}
}
After struggling with that error I finally figured out that there was a version change with webpack-cli
, yesterday I was installed webpack-cli 2.1.4
and today I installed version 3.0.0
. 在遇到这个错误后,我终于发现有一个版本更改了
webpack-cli
,昨天我安装了webpack-cli 2.1.4
,今天我安装了version 3.0.0
。 I figured it out by checking versions on npm website and i saw that it was just 5 hours passing after releasing the webpack-cli version 3
: 我通过检查npm网站上的版本来解决这个问题,我发现它在发布
webpack-cli version 3
后仅仅过了5个小时:
I should note that when I run npm run build
it just builds the folder and everything works, but I am unable run in development mode and see the result in browser. 我应该注意,当我运行
npm run build
它只是构建文件夹并且一切正常,但是我无法在开发模式下运行并在浏览器中看到结果。
I know that if I downgrade my webpack cli to previous version it must works but the question is, what is this error and how can I solve it? 我知道如果我将我的webpack cli降级到以前的版本它必须有效,但问题是,这个错误是什么,我该如何解决? (as Node packages are updated frequently it is necessary to be up-to-date, right?)
(因为节点包经常更新,所以必须是最新的,对吧?)
The new version of webpack-cli adds webpack to the global process object. 新版本的webpack-cli将webpack添加到全局流程对象。 This causes applications such as webpack-dev-derver to break since it assumes that
process.webpackModule
is available in the current process. 这会导致webpack-dev-derver等应用程序崩溃,因为它假定
process.webpackModule
在当前进程中可用。
I have created a pull request to fix this issue too https://github.com/webpack/webpack-cli/pull/478 我已经创建了一个拉取请求来修复这个问题https://github.com/webpack/webpack-cli/pull/478
试试webpack-cli v3.0.1,我会工作的。
I was able to resolve this issue by switching to the new webpack-serve ( https://github.com/webpack-contrib/webpack-serve ). 通过切换到新的webpack-serve( https://github.com/webpack-contrib/webpack-serve ),我能够解决这个问题。
From my experience, it was a very simple 1-1 drop-in replacement that only required me to alter the cli command used to load up webpack-dev-server to webpack-serve
. 根据我的经验,这是一个非常简单的1-1替代品,只需要我改变用于将webpack-dev-server加载到
webpack-serve
的cli命令。
I've opened a modification request that this should be illuminated in the README for webpack-serve: https://github.com/webpack-contrib/webpack-serve/issues/158 我已经打开了一个修改请求,这应该在webpack-serve的README中阐明: https : //github.com/webpack-contrib/webpack-serve/issues/158
After a while, today, I decided to test that again and I haven't seen a problem like that any more. 过了一会儿,今天,我决定再次测试,我还没有看到这样的问题。 I should note that today when I installed webpack-cli, npm installed webpack cli version
"webpack-cli": "^3.0.3"
and as it seems that problem is gone. 我应该注意,今天当我安装webpack-cli时,npm安装了webpack cli版本
"webpack-cli": "^3.0.3"
,因为它似乎问题已经消失。
Thanks to the webpack group for solving this, and thank you all for answering: 感谢webpack小组解决这个问题,谢谢大家回答:
@loveky and @jullian Tellez and @Even André Stensberg and @Jonny Asmar @loveky和@jullian Tellez以及@EvenAndréStensberg和@Jonny Asmar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.