JorgenVatle / meteor-vite

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

node:child_process issues on the client #239

Open dallman2 opened 15 hours ago

dallman2 commented 15 hours ago

Hey Jorgen,

I am using meteor-vite in a React codebase, with Meteor 3.0.4. Recently, I have been having trouble actually getting my dev server to launch, with the following error:

Uncaught Error: Cannot find module 'node:child_process'
    at makeMissingError (modules-runtime-hot.js?hash=740f2079be9cde2bf010e27ef9713c36c6491a66:232:12)
    at Module.resolve (modules-runtime-hot.js?hash=740f2079be9cde2bf010e27ef9713c36c6491a66:247:17)
    at Module.moduleLink [as link] (modules.js?hash=c37f9805d87eeac106d00721e598578f852ddc8d:399:25)
    at module (workers.ts:1:43)
    at fileEvaluate (modules-runtime-hot.js?hash=740f2079be9cde2bf010e27ef9713c36c6491a66:386:7)
    at Module.require (modules-runtime-hot.js?hash=740f2079be9cde2bf010e27ef9713c36c6491a66:268:27)
    at mod.require (modules.js?hash=c37f9805d87eeac106d00721e598578f852ddc8d:334:33)
    at Module.moduleLink [as link] (modules.js?hash=c37f9805d87eeac106d00721e598578f852ddc8d:406:22)
    at Helpers.ts:1:57
    at module (Helpers.ts:143:2)

I tracked it down (i think). The import chain is as follows: client.ts -> loading/vite-connection-handler -> api/Endpoints -> utility/Helpers -> workers -> node:child_process

If i understand this correctly, this import chain is causing the client to attempt to import a Node package, which obviously does not work. Is this a bug??

dallman2 commented 15 hours ago

line 16 of Endpoints.ts, which is:

const { appId } = getMeteorRuntimeConfig();

seems to be the only place that is using the offending import from Helpers. if this is the issue, can this value be parametrized in another way?

JorgenVatle commented 57 minutes ago

Huh, that's interesting. Meteor shouldn't have an issue with an import string like that. In fact, there's several other places where it's used. And I don't believe we've changed anything there recently. 😂

You're seeing this in your server logs right, not the browser?

JorgenVatle commented 29 minutes ago

We did however move the package's source files into an src subdirectory with a recent update. Which has impacted only React out of all the other example apps. Because of the new directory structure, the import path for getConfig, referenced in the React example app's react-refresh.js module would cause a similar exception. All with an arguably less than useful error message.

import { getConfig } from 'meteor/jorgenvatle:vite-bundler/loading/vite-connection-handler';

image

Updating the import path

import { getConfig } from 'meteor/jorgenvatle:vite-bundler/src/loading/vite-connection-handler';

And the problem goes away, all of a sudden the package exists again 😂