尝试部署到heroku,但控制台出现错误: Main.js:4未捕获的错误:找不到模块“ ./Sidebar/SideBar” 在webpackMissingModule(Main.js:4)
./ Sidebar / SideBar是一个React组件。之前我已经将此应用程序部署到Heroku,没有问题。另外,通常在“部署”后,第一个负载可以工作,而第二个负载则不能。
webpack.config.js
const path = require('path');
const MinifyPlugin = require('babel-minify-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
optimization: {
minimizer: [new MinifyPlugin()],
},
entry: ['babel-polyfill', './client/index.js'],
output: {
path: __dirname,
filename: './public/bundle.js',
},
mode: 'development',
devtool: 'source-map',
module: {
rules: [
{
test: /\.jsx?$/,
include: [path.resolve(__dirname, 'client')],
use: {
loader: 'babel-loader',
options: {
presets: ['env'],
},
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
},
],
},
],
},
plugins: [new CompressionPlugin()],
};
package.json
{
"name": "slack-clone",
"version": "1.0.0",
"description": "A slack clone",
"engines": {
"node": "12.16.0"
},
"main": "index.js",
"scripts": {
"heroku-prebuild": "npm install --dev",
"start": "npm run start-server & npm run build-watch",
"start-server": "nodemon server -w server",
"build-watch": "webpack -w",
"deploy": "script/deploy",
"production": "webpack -p",
"seed": "node seed.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@material-ui/core": "^4.10.1",
"@material-ui/icons": "^4.9.1",
"axios": "^0.19.2",
"bootstrap": "^3.4.1",
"compression": "^1.7.4",
"emoji-mart": "^3.0.0",
"emoji-picker-react": "^3.2.1",
"express": "^4.16.4",
"moment": "^2.27.0",
"morgan": "^1.9.1",
"pg": "^6.1.2",
"pg-hstore": "^2.3.2",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-expand-animated": "^1.0.2",
"react-hook-form": "^5.7.2",
"react-icons": "^3.10.0",
"react-redux": "^7.2.0",
"react-resizable": "^1.10.1",
"react-resize-panel": "^0.3.5",
"react-router-dom": "^4.3.1",
"react-scroll": "^1.8.0",
"react-scroll-to-bottom": "^3.0.0",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"sequelize": "^5.15.1",
"socket.io": "^1.7.2",
"webpack": "^4.29.3",
"webpack-cli": "^3.3.11"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"compression-webpack-plugin": "^4.0.0",
"css-loader": "^1.0.1",
"file-loader": "^6.0.0",
"nodemon": "^1.18.9",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"style-loader": "^0.21.0",
"uglifyjs-webpack-plugin": "^2.2.0"
}
}