Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

webpack: emitFile is not supported inside buildEnd #473

Copy link
Copy link

Description

@austinw-fineart
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't workingwebpack

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.