JorgenVatle / meteor-vite

⚡ Replace Meteor's bundler with Vite for blazing fast build-times
MIT License
28 stars 9 forks source link

bundle/ being injected into server/ #215

Open digitalextremist opened 1 day ago

digitalextremist commented 1 day ago

Pardon the premature/incomplete initial version of this issue. And also this issue has dramatically shifted around while tracing through it, so the subject only reflects the lasting issue, but I left the blow-by-blow of how I got there.


Trying to track this down, and not sure if it is this package or meteor itself... but after updating to 3.0.4 several strange things seemed to happen, top two being:

import("./bundle/meteor.server").catch((e) => console.warn('Failed to load Vite server bundle. If this is the first time starting the server, you can safely ignore this error.', e))

As I go down this sudden and unexpected rabbit hole at an update, I am all ears for what might have caused this! Otherwise will report back with the solution once I find it. Might need to roll-back to an older version and see if I can reproduce it.

digitalextremist commented 1 day ago

So far, upon rolling back I am now getting:

Error: [MeteorViteWorker] Missing required METEOR_RUNTIME environment variable

Seems like something fundamental broke somewhere. I deleted node_modules/ and package-lock.json and reinstalled with meteor npm install using a rolled-back point that worked previously, so this is disconcerting.

Will step away for a bit and return fresh, and possibly with a clue on what might have happened?

digitalextremist commented 1 day ago

( And now seeing infinite loop of: )

W20241020-20:55:12.268(-7)? (STDERR) Node.js v20.17.0
I20241020-20:55:26.551(-7)? ⚡   Refreshing configuration from Vite dev server...
W20241020-20:55:26.553(-7)? (STDERR) Oops worker process is not connected! Tried to send message to worker: { method: 'vite.server.getConfig', params: [] }
I20241020-20:55:26.553(-7)? The Vite server is likely running in the background. Try restarting Meteor. 👍
I20241020-20:55:26.555(-7)? ⚡   Refreshing configuration from Vite dev server...

This is allegedly using jorgenvatle:vite-bundler@2.0.1 but am seeing meteor-vite at version 1.11.1 as well, which I thought coincided with 2.1.3 of vite-bundler? Very strange behaviors and not yet running out ghosts and aliens.

digitalextremist commented 1 day ago

Update here... pardon the spam. Alright so, I seem to have cleaned up something and am now left with only the server/bundle/ issue for some reason. Updating the title to reflect that.

Upon roll-back this time I tried to step vite-bundler forward to 2.1.3 and that got it back to running again, once ignoring this error in the browser: image

And the error in the CLI from the above server/bundle injection:

(STDERR) Could not resolve "./bundle/meteor.server" from "server/MY_ENTRYPOINT.ts
digitalextremist commented 1 day ago

And when removing the injections, this shows until restart of the server:

image

JorgenVatle commented 23 hours ago

We shipped some changes last week that reworked how the Vite and Meteor dev servers communicate. I suspect those changes are related to the issues you're seeing.

Most likely there's a version mismatch between jorgenvatle:vite-bundler and meteor-vite. Admittedly, I was a bit quick to push out some releases for these during the upgrade, so some releases may be broken.

If you're using jorgenvatle:vite-bundler@2.1.3, make sure you also grab the latest release of meteor-vite.

meteor npm i meteor-vite@latest

Meteor will sometimes try to install older releases despite what's set in your .meteor/packages file. So it can be worthwhile to run meteor add jorgenvatle:vite-bundler@2.1.3 and then verify by checking your .meteor/versions file.

If all else fails, you can just roll back to jorgenvatle:vite-bundler@2.0.3 and meteor-vite@1.11.1 which should be stable.

JorgenVatle commented 23 hours ago

Oh, disregard all of the above. What does your vite.config.ts file look like?

  // vite.config.ts
  export default defineConfig({
    plugins: [
      meteor({
        clientEntry: "./client/main.vite.ts",
        serverEntry: "./server/main.vite.ts", // Write your server code from this entrypoint.
      }),
    ],
  });

If your plugin config looks like this, just comment out the serverEntry field. It's an experimental feature for pre-bundling your Meteor server with Vite. It needs some additional configuration to work correctly.

digitalextremist commented 14 hours ago

I use a custom name for both entry points, so it looks like this ( I just added ./ to fit your example, now ):

image

When server/bundle/ is created, there are only images in it; icons and other assets.

The disturbing thing is that the code would get an injection at all, since this type of thing ought to be built into ./dist or ./lib usually, and it diminishes trust to have artifacts added without knowledge/consent, and then that removes a feeling of sanity.

I did also do all the vite-bundler and meteor-vite attempts you mentioned there, before seeing to disregard that ( going off the original email notifications before edits ) and there was no effect. Am using latest versions of both.

digitalextremist commented 14 hours ago

To reiterate, the two issues on this are the injection of server/bundle/ and the line of code at start of serverEntry file, then also this popping on the client:

image

Right now this prevents pushing to production, but can be clicked through or ignored in the development environment.