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

⚡ Refreshing configuration from Vite dev server... #247

Closed
harry-73 opened this issue Nov 22, 2024 · 16 comments
Closed

⚡ Refreshing configuration from Vite dev server... #247

harry-73 opened this issue Nov 22, 2024 · 16 comments

Comments

@harry-73
Copy link

hi,

Meteor@3.0.3

I use, without any issues, meteor-vite@1.10.4 vite-bundler@2.0.4 with vite@4.

I am trying to upgrade, without success, to meteor-vite@1.12.0 vite-bundler@2.2.0 with vite@5.

I have the following messages:

=> Started proxy.                             
=> Started HMR server.                        
=> Meteor 3.0.4 is available. Check the changelog https://docs.meteor.com/history.html and update this project with 'meteor update'.
I20241122-18:39:18.677(1)? ⚡   Starting Vite server...
=> Started your app.

=> App running at: http://localhost:3000/

I20241122-18:39:36.409(1)? ⚡   Refreshing configuration from Vite dev server...
I20241122-18:39:38.908(1)? ⚡   Refreshing configuration from Vite dev server...
I20241122-18:39:41.409(1)? ⚡   Refreshing configuration from Vite dev server...
I20241122-18:39:43.910(1)? ⚡   Refreshing configuration from Vite dev server...
I20241122-18:39:46.436(1)? ⚡   Refreshing configuration from Vite dev server...

image

@harry-73
Copy link
Author

In vite.config.mjs :

 meteor: {
    clientEntry: 'imports/ui/main.js'
  },

@timsun28
Copy link

A potential fix that sometimes works for me is to remove your package-lock.json and node_modules folder and do a meteor reset . Afterwards reinstall npm packages with meteor npm i and run your project again.

If this doesn't fix the issue, it might have something to-do with your vite.config.ts file (could you share your current config?). And if possible, could you make a small project to replicate this issue, so others can look into your project?
If you find that in a new meteor project the issue doesn't exist, it is probably due to a meteor or npm package in your existing project, and you can try by removing most packages and see if it fixes the issue. And just add them back one by one until the issue returns.

Let me know if you need any further help!

@harry-73
Copy link
Author

harry-73 commented Nov 25, 2024

Thanks.

A potential fix that sometimes works for me is to remove your package-lock.json and node_modules folder and do a meteor reset . Afterwards reinstall npm packages with meteor npm i and run your project again.

It did not work.

I find a way to reproduce it:

Running Meteor@3.0.4

meteor create --vue meteor3-bundle
cd meteor3-bundle

Upgrade meteor-vite to 1.12.0 and vite-bundler to 2.2.0

meteor add jam:soft-delete
rm -fr .meteor/local/
rm package-lock.json
rm -fr node_modules/
meteor run

I do not know if the problem is the jam:soft-delete or meteor-vite package.

@JorgenVatle
Copy link
Owner

I suspect Meteor and Vite are unable to establish an IPC channel. Could you try with npm i meteor-vite@next and meteor add jorgenvatle:vite-bundler@3.0.0-meteor3.next.27?

@harry-73
Copy link
Author

It works. Everything seems to work except I have that error in the console:

image

@JorgenVatle
Copy link
Owner

JorgenVatle commented Dec 2, 2024

I think that could be from leftovers from the previous Meteor-Vite installation. Try to delete your _vite-bundle directory and any imports added by Meteor-Vite referencing the directory within your application source. They should be re-generated when the app is started again.

Also just shipped a new major release for Vite v6. it removes a lot of the work needed to get Meteor to work with Vite. It should address the IPC issues and the browser error you're seeing.

meteor remove jorgenvatle:vite-bundler
meteor add jorgenvatle:vite
meteor npm i meteor-vite@3 vite@6

@harry-73
Copy link
Author

harry-73 commented Dec 2, 2024

I think that could be from leftovers from the previous Meteor-Vite installation. Try to delete your _vite-bundle directory and any imports added by Meteor-Vite referencing the directory within your application source. They should be re-generated when the app is started again.

Thanks. It works. An old import was still there.

Also just shipped a new major release for Vite v6. it removes a lot of the work needed to get Meteor to work with Vite. It should address the IPC issues and the browser error you're seeing.

meteor remove jorgenvatle:vite-bundler
meteor add jorgenvatle:vite
meteor npm i meteor-vite@3 vite@6

I tried this configuration. For development, it is OK. But I try to build, I have the following error:

⚡  [PRODUCTION] Building with Vite v6.0.2...
⚡  Building packages to make them available to export analyzer...
⚡  Packages built in 28 173ms
⚡  build failed
TypeError: Cannot read properties of undefined (reading 'meteor')
    at Module.buildForProduction (file:///home/Dev/schedule/node_modules/meteor-vite/dist/bootstrap/scripts/index.mjs:32:29)

I managed to build by adding an meteorStubs entry into the vite.config.mjs file

  meteor: {
    clientEntry: 'imports/ui/main.js',
    // serverEntry: 'server/entry-vite.js',
    // enableExperimentalFeatures: false, // Required to enable server bundling.
    stubValidation: {
      warnOnly: true

      //  ignorePackages: ['meteor/alanning:roles', 'meteor/mongo']
    },
    meteorStubs: {
      meteor: {
        buildProgramsPath: ''
      }
    }
  },

@hluz
Copy link

hluz commented Dec 4, 2024

Having similar issue here.... Adding the stubValidation entry to vite.config.mjs above enables the build to complete, but causes a problem in dev:

MeteorViteStubRequestError: Unable to read file content: ENOENT: no such file or directory, open 'web.browser/packages/meteor.js' at file:///Users/hluz/(...)/app/node_modules/meteor-vite/dist/chunk-HXBBZGXY.mjs:16550:13 { package: undefined, context: undefined, cause: undefined, subtitle: undefined, metadataLines: [], originalMessage: "Unable to read file content: ENOENT: no such file or directory, open 'web.browser/packages/meteor.js'"

Any suggestions?

@JorgenVatle
Copy link
Owner

@hluz Oh, might be an issue with the new build process. Which version of meteor-vite and jorgenvatle:vite are you running? And are you on Windows by chance?

@JorgenVatle
Copy link
Owner

Oh, thanks for the heads up @harry-73 🙌 I'll get a fix out shortly.

@JorgenVatle
Copy link
Owner

JorgenVatle commented Dec 4, 2024

Oh, make sure you configure Meteor-Vite through the Vite plugin, not the deprecated "meteor" property.

Previous versions needed to have configuration overrides and defaults injected into your Vite config based on what Meteor is doing. Now it's just determined through the plugin based on the current environment. Which is more how true to how most Vite plugins are configured. Plus you should get type hints this way.

The old configuration method was deprecated a while ago but I may have forgotten to make a good note about this with recent releases. 😅 Meteor may also still be shipping skeleton apps with the old format.

// vite.config.ts
import { defineConfig } from 'vite'
+ import { meteor } from 'meteor-vite/plugin';

export default defineConfig({
    plugins: [
+    meteor({
+       clientEntry: imports/ui/main.js',
+       stubValidation:  {
+          warnOnly: true
+        },
+    }),
    ],
-  meteor: {
-    clientEntry: 'imports/ui/main.js',
-    // serverEntry: 'server/entry-vite.js',
-    // enableExperimentalFeatures: false, // Required to enable server bundling.
-    stubValidation: {
-      warnOnly: true
-      //  ignorePackages: ['meteor/alanning:roles', 'meteor/mongo']
-    },
-    meteorStubs: {
-      meteor: {
-        buildProgramsPath: ''
-      }
-    }
-  },
})

@hluz
Copy link

hluz commented Dec 4, 2024

Oh, make sure you configure Meteor-Vite through the Vite plugin, not the deprecated "meteor" property.

Previous versions needed to have configuration overrides and defaults injected into your Vite config based on what Meteor is doing. Now it's just determined through the plugin based on the current environment. Which is more how true to how most Vite plugins are configured. Plus you should get type hints this way.

The old configuration method was deprecated a while ago but I may have forgotten to make a good note about this with recent releases. 😅 Meteor may also still be shipping skeleton apps with the old format.

Ah! thanks! That was it. I hadn't noticed that change... :-(

BTW, since I have you here, do you know what are the plans for Vue 3 Tracker integration, considering that vue-meteor-tracker looks like abandonware? Noticed that some of the examples are using a "non-packaged" integration (v-meteor), which I tried but it has the same issues than vue-meteor-tracker@3.0.0-beta.7, namely, that it does not work consistently with Vue3 Options API at least. Would be great if Meteor gave that some attention.

@JorgenVatle
Copy link
Owner

Oh, I believe what you see in v-meteor is the predecessor to vue-meteor-tracker.

I'm not aware of any plans for the vue-meteor-tracker package unfortunately.

In my own projects I have a tracker implementation similar to what's available in the Vue+SSR example app (see VueMeteor.ts) this is composition-only though. If there is a real need and time allows for it, we could probably package it up and add a compatibility layer for the vue-meteor-tracker Options API.

Though, optimally there should be some initiative from the Meteor team to maintain an official tracker package for Vue similar to what they have for React.

@harry-73
Copy link
Author

harry-73 commented Dec 4, 2024

The old configuration method was deprecated a while ago but I may have forgotten to make a good note about this with recent releases. 😅 Meteor may also still be shipping skeleton apps with the old format.

! Thanks. It works. Sorry, I did not see the modification.

@hluz
Copy link

hluz commented Dec 4, 2024

I agree, there should be. I'll raise it in the Meteor Forums. Having said that, I found a way to have vue-meteor-tracker@3.0.0-beta.7 to work with the Vue 3 Options API... For anyone interested, you need to:

import { autorun } from 'vue-meteor-tracker'
...

  data() {
    return {
      myData: [],
      subReady: {},
      vueReactiveVar: '',
    },
  },
  meteor: {},
  ...

Empty meteor option is important. Then use this$subscribe inside autorun in mount capturing subReady in a data variable ($subReady does not get generated) . Something like:

...
mounted() {
    autorun(() => {
      const sub = this.$subscribe('pubName', { field: this.vueReactiveVar })
      this.subReady.pubName = sub.ready
    })
    autorun(() => {
      this.myData = MyCollection.find({ field: this.vueReactiveVar }).fetch()
    })
},
...

That is the only way that I could get it to work with full reactivity between Vue <-> Meteor worlds...

Anyway, many thanks for all you are doing with meteor-vite and for the great response!

@JorgenVatle
Copy link
Owner

Believe the original issue was addressed with a later update to meteor-vite v2.0. I'll close this for now, feel free to re-open if it re-appears. 👍

Meteor-Vite v3.0+ won't be impacted by the issue now that Vite and Meteor run under the same process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants