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

context method emitFile() is not supported in serve mode. This plugin is likely not vite-compatible. #7029

Closed
7 tasks done
code-masala opened this issue Feb 22, 2022 · 7 comments
Labels
pending triage wontfix This will not be worked on

Comments

@code-masala
Copy link

Describe the bug

I try to use this.emitFile like this

transform() {
      const css = sample(allPaths);
      this.emitFile({
        type: "asset",
        source: css,
        id: "",
        fileName: "atomic.css",
      });
    },

but emitfile is not generated a d gives warning:
context method emitFile() is not supported in serve mode. This plugin is likely not vite-compatible.
(In rollup this.emitFile is used with generateBundle instead of transform)

Is there any Changes in vite because I take the reference from rollUp

Reproduction

.

System Info

"vite": "^2.8.1"

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Feb 22, 2022

Is emitting the file required in serve/dev mode? Vite logs a warning as emitting a file in serve mode doesn't make sense (all files are kept in memory), but it will work in builds as that's a normal rollup process. If your plugin is for builds only, you can set apply: 'build' in your plugin.

@code-masala
Copy link
Author

@bluwy does this only work build mode?
Because this is not even generating the file.

@bluwy
Copy link
Member

bluwy commented Feb 22, 2022

Yeah emitFile only works in build mode (where rollup is involved). I'm not sure if it's possible to call emitFile in the transform hook, maybe that's the issue. You can try calling it in buildStart or generateBundle according to the docs.

@code-masala
Copy link
Author

@bluwy is any alternative of emitFile to use in dev mode

@bluwy
Copy link
Member

bluwy commented Feb 22, 2022

You can use fs.writeFile, but it really depends on your goal here. In some cases virtual modules would work too (link is from Vite, but it's a general pattern in rollup, just that Vite has more examples).

PS: Closing this as this is expected behaviour from Vite, and is leaning towards a discussion.

@bluwy bluwy closed this as completed Feb 22, 2022
@bluwy bluwy added the wontfix This will not be worked on label Feb 22, 2022
@code-masala
Copy link
Author

generateBuild is also not calling .
Is this due to dev?

@bluwy
Copy link
Member

bluwy commented Feb 22, 2022

There is no generateBundle in dev mode.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pending triage wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants