Difficulty running an aspnet-prerendering script through webpack #697

Closed
opened 2025-08-09 17:17:19 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @PayscaleNateW on 6/1/2017

I would like to bundle up all of my javascript using webpack. However, when passed through webpack, even your example script

var prerendering = require('aspnet-prerendering');

module.exports = prerendering.createServerRenderer(function(params) {
    return new Promise(function (resolve, reject) {
        var result = '<h1>Hello world!</h1>'
            + '<p>Current time in Node is: ' + new Date() + '</p>'
            + '<p>Request path is: ' + params.location.path + '</p>'
            + '<p>Absolute URL is: ' + params.absoluteUrl + '</p>';

        resolve({ html: result });
    });
});

will not work. That's with a very basic webpack config, such as:

...
        // bundling code for server-side rendering using Microsoft SPA Services
    {
        entry: {
            'aspnet-prerendering-bundle': './server/aspnet-prerendering-bundle.js'
        },
        output: {
            // [name] corresponds to the keys in the above entry object
            filename: '[name].js',
            path: path.resolve(__dirname, '../../../server-js/'),
            library: 'ServerRender',
            libraryTarget: 'umd'
        },
        module: {
        },
        plugins: [],
        bail: true
    }
...

The issue appears to be here: https://github.com/aspnet/JavaScriptServices/blob/dev/src/Microsoft.AspNetCore.SpaServices/npm/domain-task/src/main.ts#L43. When I simply import the module without using webpack, I get past this line just fine. However, in my webpacked bundle, this line hangs.

That binding context seems to hang indefinitely, I think because the webpacked version doesn't know what domain.active is.

The webpacked script gives the following error in the SpaServices C# code:

The Node invocation timed out after 60000ms.
You can change the timeout duration by setting the InvocationTimeoutMilliseconds property on NodeServicesOptions.

The first debugging step is to ensure that your Node.js function always invokes the supplied callback (or throws an exception synchronously), even if it encounters an error. Otherwise, the .NET code has no way to know that it is finished or has failed.
Error,   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.<InvokeExportAsync>d__13`1.MoveNext()

webpack: 2.3.3
asp-net-prerendering: 2.0.5

*Originally created by @PayscaleNateW on 6/1/2017* I would like to bundle up all of my javascript using webpack. However, when passed through webpack, even your example script ``` var prerendering = require('aspnet-prerendering'); module.exports = prerendering.createServerRenderer(function(params) { return new Promise(function (resolve, reject) { var result = '<h1>Hello world!</h1>' + '<p>Current time in Node is: ' + new Date() + '</p>' + '<p>Request path is: ' + params.location.path + '</p>' + '<p>Absolute URL is: ' + params.absoluteUrl + '</p>'; resolve({ html: result }); }); }); ``` will not work. That's with a very basic webpack config, such as: ``` ... // bundling code for server-side rendering using Microsoft SPA Services { entry: { 'aspnet-prerendering-bundle': './server/aspnet-prerendering-bundle.js' }, output: { // [name] corresponds to the keys in the above entry object filename: '[name].js', path: path.resolve(__dirname, '../../../server-js/'), library: 'ServerRender', libraryTarget: 'umd' }, module: { }, plugins: [], bail: true } ... ``` The issue appears to be here: https://github.com/aspnet/JavaScriptServices/blob/dev/src/Microsoft.AspNetCore.SpaServices/npm/domain-task/src/main.ts#L43. When I simply import the module without using webpack, I get past this line just fine. However, in my webpacked bundle, this line hangs. That binding context seems to hang indefinitely, I think because the webpacked version doesn't know what `domain.active` is. The webpacked script gives the following error in the SpaServices C# code: ``` The Node invocation timed out after 60000ms. You can change the timeout duration by setting the InvocationTimeoutMilliseconds property on NodeServicesOptions. The first debugging step is to ensure that your Node.js function always invokes the supplied callback (or throws an exception synchronously), even if it encounters an error. Otherwise, the .NET code has no way to know that it is finished or has failed. Error, at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.<InvokeExportAsync>d__13`1.MoveNext() ``` webpack: 2.3.3 asp-net-prerendering: 2.0.5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#697
No description provided.