【发布时间】:2019-12-17 23:19:18
【问题描述】:
无法成功编译 webpack 并生成 bundle.js 文件。据我了解,我的 src_dir 和 dist_dir 变量能够指向正确的路径,但在尝试编译时我仍然始终收到两个错误之一。
配置对象无效。 Webpack 已使用与 API 模式不匹配的配置对象进行初始化。 - configuration.module 有一个未知的属性 'loaders'。
&&
找不到入口模块:~我的 index.jsx 文件的完整路径~
我的 package.json
{
"name": "mypetstore",
"version": "1.0.0",
"description": "BoxKnight developer challenge ",
"main": "index.js",
"scripts": {
"build": "webpack -d --watch"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ianlennymatthews/MyPetStore.git"
},
"author": "Ian Lenny Matthews",
"license": "ISC",
"bugs": {
"url": "https://github.com/ianlennymatthews/MyPetStore/issues"
},
"homepage": "https://github.com/ianlennymatthews/MyPetStore#readme",
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/preset-react": "^7.0.0",
"axios": "^0.19.0",
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.6",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"express": "^4.17.1",
"react": "^16.8.6",
"react-bootstrap": "^1.0.0-beta.9",
"react-dom": "^16.8.6",
"webpack": "^4.35.0"
},
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"webpack-cli": "^3.3.5"
}
}
我的 webpack 配置文件
var path = require('path');
var SRC_DIR = path.join(__dirname, '/client/src');
var DIST_DIR = path.join(__dirname, '/client/dist');
module.exports = {
entry: path.join(SRC_DIR, '/index.jsx'),
output: {
filename: 'bundle.js',
path: DIST_DIR
},
module: {
rules: [
{
test: /\.jsx?/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
query: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['@babel/plugin-proposal-class-properties']
}
}
}
]
}
};
**添加文件结构
.
├── client
│ ├── dist
│ │ ├── index.html
│ │ └── style.css
│ └── src
│ ├── components
│ │ └── AddressForm.jsx
│ └── index.jsx
├── package.json
├── package-lock.json
├── README.md
├── server
│ └── index.js
└── webpack.config.js
【问题讨论】:
-
请显示您的目录结构。您发布的
webpack.config.js可能是正确的,除了index.jsx的路径。 -
@laptou 刚刚进行了编辑,谢谢
-
尝试将您的
AddressForm.jsx更改为小写(记住在任何导入时也要更改它)。过去它给我带来了麻烦。
标签: javascript webpack babeljs babel-loader