我一直在尝试使用Webpack编译我的React应用程序并收到错误:
configuration.resolve具有未知属性' root'。这些属性 有效:object {alias?,aliasFields?,cachePredicate?, descriptionFiles?,enforceExtension?,enforceModuleExtension?, extensions?,fileSystem?,mainFields?,mainFiles?,moduleExtensions?, modules?,plugins?,resolver?,symlinks?,unsafeCache ?, useSyncFileSystemCalls?
我确定目录中的文件位于正确的位置。以下是webpack.config.js
和package.json
的简要说明:
package.json
{
"name": "webpack_practice",
"version": "1.0.0",
"description": "Practicing webpack setup",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "John Doe",
"license": "ISC",
"dependencies": {
"express": "^4.15.2",
"react": "^0.14.7",
"react-dom": "^0.14.7"
},
"devDependencies": {
"babel-core": "^6.5.1",
"babel-loader": "^6.2.2",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"webpack": "^2.4.1"
}
}
webpack.config.js
module.exports = {
entry: './public/app.jsx',
output: {
path: __dirname,
filename: './public/bundle.js'
},
resolve: {
root: __dirname,
alias: {
Greeter: 'public/components/Greeter.jsx',
GreeterMessage: 'public/components/GreeterMessage.jsx',
GreeterForm: 'public/components/GreeterForm.jsx'
},
extensions: ['*', '.js', '.jsx']
},
module: {
loaders: [
{
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
},
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/
}
]
}
};
当我在resolve下添加别名时,错误就开始了。
答案 0 :(得分:1)
resolve.root
是一个webpack 1选项 - 现已弃用。我们鼓励您使用webpack 2(这是您的package.json显示的内容)。
参考:https://webpack.js.org/guides/migrating/#resolve-root-resolve-fallback-resolve-modulesdirectories,您可以看到该选项已被删除,转而使用modules
选项。