purs-loader icon indicating copy to clipboard operation
purs-loader copied to clipboard

failure to match `srcModuleRegex` leads to `null` instead of `__require__` in bundle

Open afcondon opened this issue 6 years ago • 1 comments

I'm not at all sure that this is really a bug, i'm just posting an issue so that you can consider whether it's desired behaviour.

Situation: if you have a PureScript file in which the module statement isn't the very first thing in the file then the regex defined in purs-module-map.js will fail and you'll get a null instead of the desired __require__ for the compiled JavaScript that you need in the Webpack bundle. In my case, i discovered that i'd acquired a space in front of the module name at some point.

i'm sure there are many things that could break the regex (tho probably almost all others would be caught by the compiler failing to compile the file) so it seems to me that possibly the fix, if a fix is needed, would be to raise an error whenever there isn't a match.

afcondon avatar Jul 12 '18 15:07 afcondon

Good point. Thanks for bringing this up. It is possible to write a purescript file without importing anything, so I am not sure we should raise an error if no import statements are found. Maybe a warning, but I am not sure.

I wonder if there is a better way to handle the import-to-require mappings altogether, instead of using a regex. Perhaps something that handles cases like the one where there is an extra space in front of the module name.

ethul avatar Jul 22 '18 11:07 ethul