Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Call to Node module failed with error: TypeError: Cannot read property 'filter' of undefined #358

Closed
d4rw1n1s7 opened this issue Oct 4, 2016 · 2 comments

Comments

@d4rw1n1s7
Copy link

Hi,

Following the Microsoft.AspNetCore.SpaServices tutorial, I've faced the above exception. After a little research, I've found that the exception is raised, if the webpack's configuration doesn't contain plugins field. See the following stack-trace:

System.Exception: Call to Node module failed with error: TypeError: Cannot read property 'filter' of null
    at /home/george/projects/todolist/node_modules/aspnet-webpack/LoadViaWebpack.js:80:54
    at loadViaWebpackNoCache (/home/george/projects/todolist/node_modules/aspnet-webpack/LoadViaWebpack.js:34:12)
    at Object.loadViaWebpack (/home/george/projects/todolist/node_modules/aspnet-webpack/LoadViaWebpack.js:19:49)
    at findBootModule (/home/george/projects/todolist/node_modules/aspnet-prerendering/Prerendering.js:95:29)
    at findBootFunc (/home/george/projects/todolist/node_modules/aspnet-prerendering/Prerendering.js:103:5)
    at renderToString (/home/george/projects/todolist/node_modules/aspnet-prerendering/Prerendering.js:10:5)
    at module.exports.renderToString (/tmp/tmpryJ0kL.tmp:19:46)
    at /tmp/tmpmiEDvI.tmp:113:19
    at IncomingMessage.<anonymous> (/tmp/tmpmiEDvI.tmp:132:38)
    at emitNone (events.js:86:13)
   at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.<InvokeExportAsync>d__7`1.MoveNext()

I've checked the JavaScriptServices/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/LoadViaWebpack.ts file and found that there is no test of an absent plugins field(lines 93 and 109). Since this field is not required, it needs to check that the field exists before manipulating it. As a workaround, I have added the plugins field with an empty array as its value to my configuration and all works as expected.

@d4rw1n1s7
Copy link
Author

Found a note about this issue in the Enabling Hot Module Replacement section of the mentioned tutorial:

Also, to work around a temporary issue in SpaServices, you must ensure that your Webpack config includes a plugins array, even if it's empty. For example, in webpack.config.js:

module.exports = {
    // ... rest of your webpack config is here ...

    plugins: [
        // Put webpack plugins here if needed, or leave it as an empty array if not
    ]
};

It will be better to place this note after the first example of a webpack's configuration and, in addition, provide all configuration examples with the plugins field.

@SteveSandersonMS
Copy link
Member

Thanks for the update. Yes, that was the issue. Glad it was mentioned in the docs, even if in not quite the right place :)

The latest versions of the project templates here no longer use asp-prerender-webpack-config for server-side prerendering. Instead, they contain a Webpack config that precompiles a server-side prerendering bundle so that you can use asp-prerender-module on its own without any Webpack involvement at runtime. As a result, LoadViaWebpack.ts is not used at all, and will eventually be deprecated (we're keeping it for a while for backward compatibility).

The reason for this change is because of the exact kind of issue you're reporting: it's hard to make sense of what LoadViaWebpack does behind the scenes, and not easy to extend or customise or fix problems. The new arrangement is far simpler and more explicit and would not have given you this problem :)

So, next time I update the docs, I'll change them to avoid mentioning asp-prerender-webpack-config at all, suggesting the newer technique instead. This will eliminate the issue you're reporting, as well as numerous other ones.

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

No branches or pull requests

2 participants