0

When serving lit-element components with nollup then I keep getting the following error in the browser console that I am not able to track down:

toast-messages.js:56 Uncaught TypeError: modules[number] is not a function
    at create_bindings (toast-messages.js:56)
    at toast-messages.js:57
    at Object.48 (toast-messages.js:365)
    at create_bindings (toast-messages.js:56)
    at _require (toast-messages.js:141)
    at toast-messages.js:249
    at toast-messages.js:251

Can anyone point me in the right direction? (I can share my rollup.config.js if required)

markop
  • 186
  • 11

1 Answers1

0

This error means that a module has been requested, but there's no module with the specified id (number) included in the bundle. This can happen for a variety of reasons:

  • There's a call using require passing an invalid id.
  • Passing a string or something other than a number into require.
  • Using a library that was compiled to CommonJS but was not transformed to ESM.

It's likely that you're missing the CommonJS plugin, or if you are, then the CommonJS isn't able to catch the require call and convert it. The latter can happen because of obfuscation in the library code. CommonJS plugins work by using static analysis. It would be very difficult for the plugin to transform the following:

var r = require;
r('my-library-code');

Without executing the code, it would be difficult for static analysis to track this. A best effort attempt can be made, but there will be always a situation where it could fail.

So here's the following steps you should take: * Confirm that the CommonJS plugin is being used. * If it is, check the file in node_modules for unusual patterns. * If there is, file an issue with the CommonJS plugin maintainer and see if it's possible to solve, and if not, you might need to contact the maintainer for the toast-message library.

I do realise I'm posting this very late, but better to answer later than never! To avoid this vague error in the future, in 0.10.2 of Nollup I've added a user friendly error that list some things to check for.

Hope this helps!