Skip to content

Transpiling with a Web Worker (webpack 5 worker import syntax) crashes Webpack #17105

@nakwa

Description

@nakwa

Bug report

What is the current behavior?

Transpiling with a Web Worker (webpack 5 worker import syntax) crashes Webpack

  89% sealing hashing/project/node_modules/webpack/lib/Compilation.js:4050
          otherInfo.referencedBy.push(info);
                    ^

  TypeError: Cannot read properties of undefined (reading 'referencedBy')
      at Compilation.createHash (/project/node_modules/webpack/lib/Compilation.js:4050:15)
      at /project/node_modules/webpack/lib/Compilation.js:3033:39
      at /project/node_modules/webpack/lib/Compilation.js:3280:6
      at /project/node_modules/neo-async/async.js:2818:7
      at done (/project/node_modules/neo-async/async.js:3522:9)
      at /project/node_modules/webpack/lib/Compilation.js:3243:8
      at /project/node_modules/webpack/lib/Compilation.js:3354:5
      at /project/node_modules/webpack/lib/Cache.js:93:5
      at Hook.eval [as callAsync] (eval at create (/project/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
      at Cache.get (/project/node_modules/webpack/lib/Cache.js:75:18)
      at ItemCacheFacade.get (/project/node_modules/webpack/lib/CacheFacade.js:111:15)
      at Compilation._codeGenerationModule (/project/node_modules/webpack/lib/Compilation.js:3322:9)
      at /project/node_modules/webpack/lib/Compilation.js:3229:11
      at arrayIterator (/project/node_modules/neo-async/async.js:3467:9)
      at processTicksAndRejections (node:internal/process/task_queues:78:11)
  error Command failed with exit code 1.

If the current behavior is a bug, please provide the steps to reproduce.

Webpack config (partial export):

  {
    mode: 'development',
    target: 'web',
    entry: {
      app: './app/client/app.js'
    },
    output: {
      globalObject: 'this',
      path: '/project/app/assets/builds',
      filename: '[name].js',
      chunkFilename: '[name]-[contenthash].digested.js',
      sourceMapFilename: '[file]-[fullhash].digested.map',
      hashFunction: 'sha256',
      hashDigestLength: 64
    },
    plugins: [
      CaseSensitivePathsPlugin {
        options: {},
        logger: [Object [console]],
        pathCache: Map(0) {},
        fsOperations: 0,
        primed: false
      },
      DefinePlugin { definitions: [Object] },
      MinChunkSizePlugin { options: [Object] },
      NodePolyfillPlugin { options: [Object] },
      Dotenv { config: [Object] }
    ],
    optimization: { minimizer: [], nodeEnv: false, splitChunks: { chunks: 'async' } },
    performance: { hints: 'warning' },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /(node_modules)/,
          use: { loader: 'babel-loader' }
        },
        {
          // not this worker
          test: /some-other-specific-node_module-worker-file\.js/,
          type: 'asset/resource',
          generator: { filename: '[name]-[contenthash].digested[ext]' }
        }
        // ... some other rules for fonts and style (non-js extensions, should not matter)
      ]
    },
    node: { __filename: false, __dirname: false, global: true },
    resolve: {
      alias: {
        // ... some more aliases 
        workers: '/project/app/client/workers'
      },
      fallback: { fs: false, net: false, tls: false }
    },
    stats: { preset: 'errors-warnings', children: true },
    watchOptions: {
      ignored: /node_modules/,
      aggregateTimeout: 1000,
      followSymlinks: true
    },
    devtool: 'eval'
  }

File using worker:

  const myWorker = new Worker(
    new URL('workers/myworker.worker.js', import.meta.url)
  );

  // ....

  async someFunction(data) {
    return new Promise((resolve, reject) => {
      myWorker.onmessage = () => {
        // do stuff
      }
      myWorker.postMessage(data)
    });
  }

Worker:

  import 'core-js/stable';
  import 'regenerator-runtime/runtime';

  onmessage = async (data) => {
    // not doing anything
  };
  
  // Actually, an empty file compiles, but any code at all seems to crash the webpack (even just a console.log statement)

What is the expected behavior?

Not to crash.

Other relevant information:

  System:
    OS: macOS 13.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 122.82 MB / 16.00 GB
  Binaries:
    Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.18.1/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
  Browsers:
    Chrome: 112.0.5615.137
    Firefox: 112.0.2
    Safari: 16.4
  Packages:
    babel-loader: ^9.1.2 => 9.1.2
    case-sensitive-paths-webpack-plugin: ^2.4.0 => 2.4.0
    css-loader: ^6.7.3 => 6.7.3
    dotenv-webpack: ^8.0.1 => 8.0.1
    file-loader: ^6.2.0 => 6.2.0
    node-polyfill-webpack-plugin: ^2.0.1 => 2.0.1
    style-loader: ^3.3.2 => 3.3.2
    terser-webpack-plugin: ^5.3.7 => 5.3.7
    webpack: ^5.78.0 => 5.80.0
    webpack-cli: ^5.0.1 => 5.0.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Priority - High

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions