Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Typo in createOutputWriter.js #441

Open
JackTiber opened this issue Nov 20, 2021 · 3 comments
Open

Possible Typo in createOutputWriter.js #441

JackTiber opened this issue Nov 20, 2021 · 3 comments

Comments

@JackTiber
Copy link

Describe the bug
On line 51 of lib/output/createOutputWriter.js the local variable localFs is either filestream or the fs module from Node, but on line 88 the method localFs.mkdirp is called to output the json file. The resulting error during a build is below.

localFs.mkdirp(options.path, mkdirCallback);
              ^
TypeError: localFs.mkdirp is not a function

Changing this to localFs.mkdir seems to fix the issue.

To Reproduce
Steps to reproduce the behavior:

  1. Install at 7.1.1
  2. Set options.keepInMemory to true
  3. Run build

Expected behavior
For the JSON file to be output correctly in memory.

Webpack Config

const path = require("path");
const resolve = require("path").resolve;
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const AssetsPlugin = require("assets-webpack-plugin");

const runEnv = process.env.NODE_ENV || "development";

module.exports = {
    entry: "./src/index.tsx",
    output: {
        path: resolve(__dirname, "dist"),
        filename: runEnv === "production" ? "[name].[hash].js" : "bundle.js",
        publicPath: runEnv === "production" ? "/request" : "/",
    },
    target: "web",
    mode: runEnv,
    devtool: runEnv === "production" ? "cheap-source-map" : "eval-source-map",
    devServer: {
        contentBase: path.join(__dirname, "dist"),
        port: 3003,
        historyApiFallback: true,
        openPage: "/request",
        hot: true,
    },
    resolve: {
        extensions: [".ts", ".tsx", ".js", ".json"],
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: "babel-loader",
                exclude: /node_modules/,
            },
            {
                test: /\.svg$/,
                use: ["@svgr/webpack", "url-loader"],
            },
            {
                test: /\.(png|pdf|jpg|eot|woff|woff2|ttf|gif)$/,
                oneOf: [
                    {
                        loader: "url-loader",
                        options: {
                            limit: 9000,
                        },
                    },
                ],
            },
        ],
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: "index.html",
            template: "src/index.html",
            excludeChunks: ["server"],
        }),
        new CopyPlugin({
            patterns: [
                {
                    from: "./src/_assets",
                    to: "assets",
                },
            ],
        }),
        new NodePolyfillPlugin(),
        new AssetsPlugin({
            filename: "bundlePath.json",
            fullPath: false,
            path: path.join(__dirname, "dist"),
            includeAllFileTypes: false,
            fileTypes: ["js"],
            keepInMemory: true,
        }),
    ],
};

Desktop (please complete the following information):

  • OS: Win 11
  • Node version: 16.13.0 LTS
  • Plugin version: 7.1.1

Additional context
Add any other context about the problem here.

@JackTiber
Copy link
Author

Actually, looking at the file history it looks like the dependency for mkdirp was just removed from this version but changed back to localFs.mkdirp from localFs.mkdir.

@wmertens
Copy link
Contributor

wmertens commented Nov 3, 2022

Ran into the same thing. Can't use the plugin with webpack-middleware-dev like this.

@LP1994
Copy link

LP1994 commented Feb 19, 2024

Actually, looking at the file history it looks like the dependency for mkdirp was just removed from this version but changed back to localFs.mkdirp from localFs.mkdir.

Here's my main version info:
node: 21.6.2
npm : 10.4.0
webpack: 5.90.3
webpack-cli: 5.1.4
webpack-dev-middleware: 7.0.0
webpack-dev-server: 5.0.2
webpack-sources: 3.2.3
assets-webpack-plugin: 7.1.1

At some point, when I upgraded to the above mentioned "npm package", I got the same error.Until then, it had been running fine.That's weird.

Personally, I think it's due to the recent "webpack" update that removed the outdated "mkdirp", see:
https://webpack.js.org/blog/2020-10-10-webpack-5-release/#filesystems

Then, after I changed "mkdirp" to "mkdir" as you said, it triggered a new error.
image

After troubleshooting, the final change to this worked:
localFs.mkdir(options.path, { recursive: true }, mkdirCallback);

This issue was created a long time ago, but I'm posting the problem I encountered and the solution for your reference.

Den-dp added a commit to Den-dp/assets-webpack-plugin that referenced this issue Feb 5, 2025
…changes

Fixing `TypeError: localFs.mkdirp is not a function`, caused by the migration from `memfs@3` to `memfs@4` in webpack/webpack-dev-middleware#1693, where `mkdirp` was removed. See: https://github.com/streamich/memfs/releases/tag/v4.2.0

Refs: ztoben#441
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants