-
-
Notifications
You must be signed in to change notification settings - Fork 921
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
nodeLoader is undefined - global.nodeLoader.setImportMapPromise(Promise.resolve(nodeImportMap)) #1173
Comments
Hi, did you manage to solve the issue? |
While searching for a solution to this same issue I landed on this bug. A little more research and debugging and I've figured out the issue. Node 20 broke loaders that need to keep state. From my cursory investigation, Node 20 now loads loaders outside the main thread so global.nodeLoader is defined in one thread but not in the main thread. Apparently they are moving away from --experimentalLoader and --loader switched to using an --import switch and calling the init callback of the loader to get access to parameters to talk to the main thread. My solution for now is to back off to Node 18 but if I find some time I may want to tackle this bug and provide a more robust way to initialize the loaders. Nodejs issue for context - nodejs/loaders#147 |
That's right and for this I decided to change my strategy. I believe that Node.js does this for security reasons among others and seems there is no plan to change the address in the future. Now what I do is not import any module in that way, but instead process the HTML template directly from the backend with ExpressJS and a custom implementation. The template is served and used by the client, then the rest of mfes not need to be server side in my case. |
Even 18 doesn't work. I think the right approach here is to load the import maps in the main thread and build some communication channel to request the data in both userland (e.g. during the request) and in the loaders so we don't have to have duplicate pollers. |
@rgallego87 Waiting to be able to join the slack servers so I can discuss further. Though I have managed to fix a number of issues and have my child SPAs importing from the network, I have come to the same conclusion that arbitrary network imports aren't going to work for security reasons. My plan now is to move SSR down to the individual SPAs and have the layout simply inject the SSR rendered html. At first they will all be rendered per usual through separate server instances but then I would like to make a single generic express server that can serve up the apps via s3 or similar so I don't have to deploy a new service every time I deploy a new SPA. |
NodeJS has messed with the loaders API many times - it is no longer necessary to use I recommend upgrading to the latest versions of Node and switching to |
Hello, I would like to address a couple of issues I'm encountering during the implementation of an important project. It's a microfrontends project aiming to use SSR (Server-Side Rendering), and for this purpose, I've drawn inspiration from the isomorphic-microfrontends example.
Describe the bug or question
One of the main issues I'm facing is that when using:
tsx watch --clear-screen=false --experimental-network-imports --experimental-loader @node-loader/core server/server.ts
global.nodeLoader.setImportMapPromise(Promise.resolve(nodeImportMap)); <-- nodeLoader is undefined and I believe it's crucial for the rest of the flow to work, namely the import of the apps within the renderApplication and other aspects.
To Reproduce
tsx watch --clear-screen=false --experimental-network-imports --experimental-loader @node-loader/core server/server.ts and when you invoke localhost:9000 it fails with:
TypeError: Cannot read properties of undefined (reading 'setImportMapPromise')
Main Context
Node.js Version: 20.3.1
App inspired by: isomorphic-microfrontends example
Root-app:
What could I do? Are there any examples like this with these updated versions? Any incompatibility I should be aware of? Any suggested changes or alterations?
Thank you in advance!
The text was updated successfully, but these errors were encountered: