question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bluwycommented, 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.

1reaction
bluwycommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

context method emitFile() is not supported in serve mode. This ...
This is in my svelte.config.js transform() { const css = getAtomicCss(allPaths); this.emitFile({ type: "asset", source: css, ...
Read more >
Plugin API - Vite
Virtual modules are a useful scheme that allows you to pass build time information to the source files using normal ESM import syntax....
Read more >
rollup ModuleInfo TypeScript Examples - ProgramCreek.com
emitFile is not supported in transform mode. This plugin is likely not compatible`); } else if (source) { fs.writeFileSync(filename, source); } return id; ......
Read more >
Troubleshooting | Vite Ruby
If you are using a non-standard setup, try configuring viteBinPath . Your bin/bundle was not generated by Bundler #. It's likely that your...
Read more >
Using the VitePWA Plugin for an Offline Site | CSS-Tricks
A service worker is a background process that runs on a separate thread in your web application. Service workers have the ability to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found