I am not sure what I updated in my React project, but I started getting a parsing error trying to build my project. I am certain (honestly) that this worked fine some time in the recent past. (source file is a .tsx file) Thoughts?
const titles = new Map<number, string>();
resources.forEach((e: any) => {
// titles.set(
// e.StoreHierarchyValueId ?? e.SkuHierarchyValueId, e.Value
// )
if (e.StoreHierarchyValueId)
titles.set(e.StoreHierarchyValueId, e.Value);
else
titles.set(e.SkuHierarchyValueId, e.Value);
});
When I had the commented out code in place, "npm run build" would error out with the following less than helpful (to me) message:
Module parse failed: Unexpected token (51:822) You may need an appropriate loader to handle this file type. | // [] | // ); function retrieveCustomerResources(){console.log('"',env,'", "',customer,'"');if(env!==''&&env!==undefined&&customer!==''&&customer!==undefined){setLoadingResources(true);axios.get("/"+props.urlPart+"Hierarchy/"+env+"/"+customer).then(function(response){setResources(response.data);}).catch(function(error){console.log(error);}).then(function(){setLoadingResources(false);});}}if(env==="")return/#PURE/React.createElement("div",null,"No HT environment seleted");if(loadingResources){return/#PURE/React.createElement("div",null,"Loading "+props.urlPart+" Data for..."+customer);}if(resources===null||resources.length===0){return/#PURE/React.createElement("div",null,"No "+props.urlPart+" Data for..."+customer);}var titles=new Map();resources.forEach(function(e){return titles.set(e.StoreHierarchyValueId??e.SkuHierarchyValueId,e.Value);});var parentMap=new Map();resources.forEach(function(f){f.subRows=[];parentMap.set(f.StoreHierarchyValueId??f.SkuHierarchyValueId,f.subRows);});resources.forEach(function(f,_i){var v=parentMap.get(f.ParentId);if(!v){parentMap.set(f.ParentId,[f]);}else{v.push(f);}});var data=resources.filter(function(e){return e.ParentId===0;});// function Table({ columns, data, renderRowSubComponent } | // : { columns: any, data: any, renderRowSubComponent: any } | // ): any {
The problematic code was no where near line 51. The only way I figured this out was by commenting out sections of code until it compiled successfully.
Thanks to @Mike'Pomax'Kamermans and @epascarello. It was definitely my tooling options.
I was using eslint and typescript. My .tsconfig file had a target of "es5" (not sure how that got set, but anyways...) Once I changed it to ES6, the problem naturally went away.