node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7k stars 680 forks source link

Cannot find module 'xxx/plugins/octetstream.js' when use webpack for packaging #883

Closed ching2018 closed 1 year ago

ching2018 commented 1 year ago

webpack.config.js:

const path = require("path");
const NodemonPlugin = require("nodemon-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const { NormalModuleReplacementPlugin } = require("webpack");
module.exports = {
  entry: "./server/server.js",
  target: "node",
  plugins: [
    new NodemonPlugin(),
    new NormalModuleReplacementPlugin(
      /^hexoid$/,
      require.resolve("hexoid/dist/index.js")
    ),
  ],
  output: {
    path: path.resolve(__dirname, "server"),
    filename: "index.js",
    libraryTarget: "commonjs2",
  },
  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env"],
          },
        },
      },
    ],
  },
  optimization: {
    minimizer: [new TerserPlugin({ terserOptions: { mangle: false } })],
  },
};

server.js:

const fs = require("fs");
const path = require("path");
const os = require("os");
const Koa = require("koa2");
const koaBody = require("koa-body");
const KoaStatic = require("koa-static");
const cors = require("@koa/cors");
const { historyApiFallback } = require("koa2-connect-history-api-fallback");
const router = require("./router");

const platform = os.platform();
const app = new Koa();

app.use(historyApiFallback({ whiteList: ["/api"] }));
app.use(KoaStatic("./dist"));
app.use(
  koaBody({
    multipart: true,
    formidable: {
      maxFileSize: 2000 * 1024 * 1024,
      uploadDir:
        platform == "darwin"
          ? `/app.nw/`
          : `./`,
      keepExtensions: true,
    },
  })
);
app.use(router.routes());

console.log("SERVER_PORT", process.env.SERVER_PORT);
app.listen(process.env.SERVER_PORT || 3000);
GrosSacASac commented 1 year ago

Maybe it is an issue in koa-body