JorgenVatle/meteor-vite

Cannot run "meteor run --production"

Closed this issue ยท 6 comments

I can't successfully execute "meteor run --production" on Windows.

If I try it on project with packages folder, I get the following error:
1  with packages

And if I remove packages, the server starts, but JS application code (client.js, clientChild.js) is not loaded on client.
2  no packages

Hi @JorgenVatle,

do you have any news on this? We have the same problem with the production build. When using mup or meteor build --production the build is stuck.

First it got stuck at this:

Build successful (148816.44ms)

Then I added a Close() plugin in the vite.config.js

`export default function ClosePlugin() {
return {
name: 'ClosePlugin', // required, will show up in warnings and errors

    // use this to catch errors when building
    buildEnd(error) {
        if(error) {
            console.error('Error bundling')
            console.error(error)
            process.exit(1)
        } else {
            console.log('Build ended')
        }
    },

    // use this to catch the end of a build without errors
    closeBundle(id) {
        console.log('Bundle closed')
        process.exit(0)
    },
}

}`

Now it seems to be stuck at this:

Loading plugin vite from package `j...

I would really appreciate some help here, cuz we want to get the deployment with vite live.

Thx โ˜บ๏ธ

I do have a branch in the works that resolves this issue. However, with the way we're feeding Vite's build output into Meteor for production, you may end up seeing some of your project's source files being modified during the build process. When running Meteor in --production mode, those modifications need to persist until the server shuts down. And if Meteor doesn't exit cleanly those modifications are never cleaned up and may inadvertently be committed into version control by a developer.

So I've opted not to ship this until we can come up with a better solution that's not as dangerous. If anyone with some knowledge around the Meteor build process has any ideas on including additional JavaScript into the client bundle without having to modify the project's source, I'd appreciate any help I can get on this. ๐Ÿ™

Here is my Workaround. Not pretty, but maybe it helps someone:

We wanted Vite for local deployment, not for production, so I just removed it in the ci/cd process. Here is my script

`#deploy.sh

start remove vite for deployment

meteor remove jorgenvatle:vite-bundler
npm uninstall meteor-vite vite vite-jsconfig-paths vite-jsconfig-paths vite-plugin-eslint vite-plugin-node-polyfills vite-plugin-stylelint vite-tsconfig-paths
rm vite.config.js
rm ./server/react-refresh.js
cp .deploy/viteRemovalFiles/mainServer.ts ./server/main.ts
cp .deploy/viteRemovalFiles/mainClient.ts ./client/main.ts

end remove vite

`

`//mainServer.ts

// removed by deployment
//import './react-refresh'; // Server entry point, imports all server code

/**

  • Import all your Meteor methods and publications.
    */
    import '/imports/startup/both';
    import '/imports/startup/server';
    import './methods/blocks';
    `

`//mainClient.ts
import 'meteor/react-meteor-data';

import '../imports/startup/client';
`

-> Make sure you delete node_modules on the deployment Server and make a meteor reset just in case there is old stuff in there

This should now be resolved with meteor-vite@1.5.0 and jorgenvatle:vite-bundler@1.7.0. Let me know if you run into any issues. ๐Ÿ™Œ

This should now be resolved with meteor-vite@1.5.0 and jorgenvatle:vite-bundler@1.7.0. Let me know if you run into any issues. ๐Ÿ™Œ

Thank you very much for your work!

There are 3 non-critical comments:

  1. For the Windows system, the path to the production package in the clientFake.js file is not generated quite correctly, which is why a launch error occurs:
    vivaldi_7pDgpgpoSD
    This happens because of the way nodejs treats paths across systems by default. Please process paths for the clientFake.js file, replacing backslashes with slashes. If you replace it manually, then everything works correctly.
  2. When restarted in production mode, the generated path and comment are duplicated.
  3. When running in developer mode, the generated path remains. If it is not technically difficult, delete (or comment out) this path automatically. But if itโ€™s difficult, then itโ€™s okay, since in this mode launches will not be frequent and manual removal is not difficult.

Oops. Give it a try with jorgenvatle:vite-bundler@1.7.2