modules.js?hash=1366dc073b25c0d88856bae23f6e79534ab11087:7168 Uncaught (in promise) TypeError: Cannot convert object to primitive value
at modules.js?hash=1366dc073b25c0d88856bae23f6e79534ab11087:7168
at Array.map (<anonymous>)
at printWarning (modules.js?hash=1366dc073b25c0d88856bae23f6e79534ab11087:7167)
at error (modules.js?hash=1366dc073b25c0d88856bae23f6e79534ab11087:7147)
at modules.js?hash=1366dc073b25c0d88856bae23f6e79534ab11087:8527
at meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:1234
A quick Google search suggests that this is caused by an out-of-date JQuery version. That seemed logical as I am using jquery@1.11.0 (because of package constraints).
I tried to install jquery@3.4.1 using the --allow-incompatible-update flag but Meteor says error: no such version jquery@3.4.1. Same for 3.5.1. Same error when using !. Highest version I can install is 3.0.0. This did not fix the error though.
I installed 3.4.1 with NPM instead. This also did not work. I’m not even 100% sure if this is a JQuery problem but the only solutions I can find are related to JQuery.
I’m importing with:
const Home = lazy(() => import('./pages/home/Home'));
My render looks like this (I’ve removed a lot of code - included what I think is relevant):
@juanpmd up till now I have been using React.lazy in a similar way as you demonstrate with @loadable/component. However, dynamic imports cause an issue with the Content Security Policy. I have to allow unsafe-eval to make it work. Do you have similar experiences with @loadable/component?
They both work in a simillar way. I tried React Lazy Loading a while ago and I remember choosing loadable/component for 2 reasons:
React Lazy had some strange white flickering which I though was not optimal for users.
@loadable/component has a wonderful preload feature. For example you can lazy load a modal on a view, if you hover a button (without clicking) this will preload the Modal and when you click it is already there.
A post would be wonderful, thank you @filipenevola . I tried using the Meteor dynamic import system with React but I was never able to make it work (with Blaze it was extremelly easy). After that I used react-loadable which was deprecated and jumped into @loadable/component.
I would very much appreciate a post about this subject @filipenevola. As I mentioned in my previous comment, I trying to figure out how dynamic imports relate to Content Security Policy settings. It seems that dynamic imports on the client require certain settings (i.e. allowing unsafe-eval) that are not favorable.
@cstrat Yes, this will exclude that package from your initial bundle too.
Check the bundle visualizer to confirm; if you still see that package in the bundle, find out where else it is referenced from. Consider using madge in non-trivial cases:
Madge is a developer tool for generating a visual graph of your module dependencies, finding circular dependencies, and give you other useful info. Joel Kemp’s awesome dependency-tree is used for extracting the dependency tree.
Works for JavaScript (AMD, CommonJS, and ES6 modules)
Also works for CSS preprocessors (Sass, Stylus, and Less)
NPM installed dependencies are excluded by default (can be enabled)
All core Node.js modules (assert, path, fs, etc) are excluded