gpt4 book ai didi

javascript - 网络包 : Invalid configuration object/Invalid Module Entry

转载 作者:行者123 更新时间:2023-12-02 23:09:23 28 4
gpt4 key购买 nike

无法成功编译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 documentation意味着 context 是必要的,并且 entry 应该是 context 的相对路径。

module.exports = {
context: path.resolve(__dirname, 'app'),
entry: "./home.js"
};

尝试将 webpack.config.js 修改为如下所示:

module.exports = {
context: SRC_DIR,
entry: "./index.jsx",
// ...
};

关于javascript - 网络包 : Invalid configuration object/Invalid Module Entry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57443206/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com