Skip to content

Random crash  #229

Closed
Closed

Description

@malj
  • Webpack Version: 5.47.9
  • Operating System (or Browser): Ubuntu 20.04.2 (WSL 2)
  • Node Version: 16.6.0
  • webpack-plugin-serve Version: 1.5.0

How Do We Reproduce?

Run Webpack CLI in watch mode with the following config:

new ServePlugin({
    progress: "minimal",
    host: "localhost",
    hmr: "refresh-on-failure",
})

Expected Behavior

No crashes

Actual Behavior

Webpack process randomly crashes after a while (cca 15 minutes on my machine with Intel i7-8750H and 32 GB RAM) with the following console output:

[webpack-cli] TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at stringify (/path/to/my/project/node_modules/json-stringify-safe/stringify.js:5:15)
    at prep (/path/to/my/project/node_modules/webpack-plugin-serve/lib/routes.js:15:24)
    at WebpackPluginServe.<anonymous> (/path/to/my/project/node_modules/webpack-plugin-serve/lib/routes.js:103:58)
    at WebpackPluginServe.emit (node:events:406:35)
    at WebpackPluginServe.emit (/path/to/my/project/node_modules/webpack-plugin-serve/lib/index.js:158:13)
    at /path/to/my/project/node_modules/webpack-plugin-serve/lib/index.js:210:35
    at Hook.eval [as callAsync] (eval at create (/path/to/my/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:42:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/path/to/my/project/node_modules/tapable/lib/Hook.js:18:14)
    at Watching._done (/path/to/my/project/node_modules/webpack/lib/Watching.js:273:28)

Related issues:

Activity

  1. shellscape commented on Aug 7, 2021

    @shellscape
    Owner

    This is an issue with json-stringify-safe, not this lib.

  2. malj commented on Aug 7, 2021

    @malj
    Author

    I know, I submitted a PR, but the lib was last updated in 2015 so I'm not expecting it to be merged anytime soon.

    I'm not even sure where big ints are coming from because I'm not using them in my code, but the fix seems fairly trivial. I was hoping you'd consider patching it with a custom replacer, if it wouldn't affect anything else. It's a bit tedious having to kill orphaned child processes and restart webpack several times per hour while working with this plugin.

  3. shellscape commented on Aug 7, 2021

    @shellscape
    Owner

    Yeah the last thing I want to do is handle stringifying myself. Not a fun thing. You might be able to contact the maintainer via Twitter or email.

  4. cahnory commented on Sep 21, 2021

    @cahnory

    While this is not solved, here's a very dirty hack (but at least it'll only affect tooling code) to put in your webpack config file:

    /**
     * This hack is used to prevent an annoying issue
     * with a dependency of webpack-plugin-serve:
     * - https://github.com/shellscape/webpack-plugin-serve/issues/229
     *
     * It only runs when bundling and is NOT PRESENT in bundled code
     */
    const nativeJSONStringify = JSON.stringify
    const bigIntReplacer = (key, input) => {
      if (typeof input !== 'bigint') {
        return input
      }
    
      return `${input}`
    }
    JSON.stringify = (input, replacer, space) => {
      let output = input
    
      if (
        Array.isArray(replacer) &&
        typeof output === 'object' &&
        !Array.isArray(output)
      ) {
        output = Object.fromEntries(
          Object.entries(output).filter(([key]) => replacer.includes(key)),
        )
      }
    
      return nativeJSONStringify(
        output,
        typeof replacer === 'function'
          ? function intermediateReplacer(key, value) {
              return replacer.call(this, key, bigIntReplacer(key, value))
            }
          : bigIntReplacer,
        space,
      )
    }

    Note that the replacer part has not been heavily tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions