我收到了这条消息,请帮忙......先谢谢。 ...
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.module has an unknown property 'loaders'. These properties are valid:
object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
-> Options affecting the normal modules (`NormalModuleFactory`).
- configuration.resolve.extensions[0] should not be empty.
-> A non-empty string
我在webpack中的配置是这样的,我还在试图弄清楚为什么会发生这种情况......我的文件是:https://github.com/NodeioLabs/Theatherflix/blob/master/webpack.config.js
答案 0 :(得分:1)
从第7-14行和第37-46行,您会注意到:
resolve: {
root: __dirname,
alias: {
Main: 'app/components/Main.jsx',
Nav: 'app/components/Nav.jsx',
ListM: 'app/components/ListM.jsx',
About: 'app/components/About.jsx'
},
extensions: ['', '.js', '.jsx']
},
和
extensions: [".js", ".json"]
webpack不接受,我建议你使用webpack resolve.extensions
推荐的自动解决某些扩展程序。默认为:
root: __dirname,
alias: {
Main: 'app/components/Main.jsx',
Nav: 'app/components/Nav.jsx',
ListM: 'app/components/ListM.jsx',
About: 'app/components/About.jsx'
},
在这里:
alias: {
Main : path.resolve(__dirname, 'app/components/Main'),
Nav: path.resolve(__dirname, 'app/components/Nav'),
ListM: path.resolve(__dirname, 'app/components/ListM'),
About: path.resolve(__dirname, 'app/components/About')
},
的建议使用此格式
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
我希望这会有所帮助。
答案 1 :(得分:0)
让我们独立查看消息:
configuration.module has an unknown property 'loaders'.
表示您目前拥有:
{
module: {
loaders: {}
}
}
所以将loaders
更改为rules
(根据webpack documentation):
{
module: {
rules: {}
}
}
configuration.resolve.extensions[0] should not be empty.
表示你有:
{
resolve: {
extensions: ['']
}
}
所以从extensions
中删除空字符串:
{
resolve: {
extensions: []
}
}
答案 2 :(得分:0)
我在为答案苦苦挣扎……我不得不进行大量研究。但是,我找到了答案,或者找到了解决这种情况的出路:
首先:创建一个.babel-rc文件
/*
./.babelrc
*/
{
"presets":[
"es2015", "react"
]
}
还要考虑此程序包json文件:
{
"name": "theatherflix",
"description": "",
"main": "server.js",
"scripts": {
"webpack": "webpack --progress",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config webpack.config.js"
},
"author": "Nodeio Labs",
"license": "GPL-3",
"dependencies": {
"@babel/preset-react": "^7.0.0-beta.51",
"axios": "^0.18.0",
"babel": "^6.23.0",
"docker": "^1.0.0",
"express": "^4.13.4",
"extract-text-webpack-plugin": "^3.0.2",
"find-process": "^1.1.0",
"loader": "^2.1.1",
"material-ui": "^0.20.1",
"modules": "^0.4.0",
"path": "^0.12.7",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"react-router": "^2.0.0",
"redux": "^4.0.0",
"redux-thunk": "^2.2.0",
"ts-loader": "^4.4.1",
"uuid": "^3.2.1",
"webpack-dev-server": "^3.1.4"
},
"devDependencies": {
"@babel/core": "^7.0.0-beta.51",
"@babel/preset-env": "^7.0.0-beta.51",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.5.0",
"fuse-box": "^3.2.2",
"gulp-babel": "^7.0.1",
"jsx-loader": "^0.13.2",
"node-sass": "^4.9.0",
"typescript": "^2.9.2",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.2"
}
}
*使用此模块包中的所需内容。
然后我在Webpack中更正几行:
/*
./webpack.config.js
*/
const path = require('path');
module.exports = {
mode: "none",
entry: './app/app.jsx',
output: {
path: path.resolve('public'),
filename: 'bundle.js'
},
module: {
rules: [{
test: /\.css$/,
use: [{
loader: "style-loader"
},
{
loader: "css-loader"
}
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: "babel-loader"
}, {
test: /\.jsx?$/,
exclude: /node_modules/,
use: "babel-loader"
}
]
}
}
这是我的app.jsx:
var React = require('react');
var ReactDOM = require('react-dom');
var {Route, Router, IndexRoute, Main, About, MovieList, hashHistory} = require('react-router');
var Main = require('./components/Main.jsx');
var MovieList = require('./components/MovieList/MovieList.jsx');
var About = require('./components/About/About.jsx');
//import './app.scss';
ReactDOM.render(
<Router history={hashHistory}>
<Route path="/" component={Main}>
<Route path="about" component={About}/>
<IndexRoute component={MovieList}/>
</Route>
</Router>,
document.getElementById('app')
);
我希望它可能对其他人有帮助。