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

webpack: emitFile is not supported inside buildEnd #473

Open
austinw-fineart opened this issue Feb 8, 2025 · 0 comments
Open

webpack: emitFile is not supported inside buildEnd #473

austinw-fineart opened this issue Feb 8, 2025 · 0 comments
Labels
bug Something isn't working webpack

Comments

@austinw-fineart
Copy link

austinw-fineart commented Feb 8, 2025

Environment

Node: v22.13.1
unplugin: 2.1.2

Reproduction

import { createWebpackPlugin } from 'unplugin';

export default createWebpackPlugin((rawOptions = {}) => {
  return {
    buildEnd() {
      this.emitFile({
        fileName: 'test.json',
        source: '{}',
        type: 'asset',
      });
    }
  };
});

Describe the bug

Not sure if this is a bug or oversight but

throw new Error('unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)')

buildEnd is not a supported hook for emitFile, as far as webpack is concerned. The reason is because compilation is sealed before emit which is what buildEnd hooks.
https://github.com/webpack/webpack/blob/f123ce5090e56ce1216debce487e8be25275b896/lib/Compiler.js#L1341
Thus you get TypeError: Cannot add property test.json, object is not extensible
So either emitFile isn't supported or buildEnd is using the wrong hook.

Additional context

webpack/webpack#10876

@austinw-fineart austinw-fineart added the bug Something isn't working label Feb 8, 2025
@sxzz sxzz added the webpack label Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working webpack
Projects
None yet
Development

No branches or pull requests

2 participants