atomicdata-dev / atomic-data-browser

This repo is no longer used! Code is moved to Atomic-Server
https://github.com/atomicdata-dev/atomic-server/issues
MIT License
56 stars 9 forks source link

Build issue webpack / snowpack #31

Closed joepio closed 3 years ago

joepio commented 3 years ago

npm run build is failing (since.. upgrading most dependencies).

throwing errors like this:

Module parse failed: Unexpected token (1:935)
File was processed with these loaders:
 * ../node_modules/babel-loader/lib/index.js
 * ../node_modules/@snowpack/plugin-webpack/plugins/import-meta-fix.js
 * ../node_modules/@snowpack/plugin-webpack/plugins/proxy-import-resolve.js
You may need an additional loader to handle the result of these loaders.
> import React,{useState}from"../../pkg/react.js";import{useArray}from"../../atomic-react/hooks.js";import{ButtonMargin}from"../Button.js";import{ErrMessage}from"./InputStyles.js";import{ResourceSelector}from"./ResourceSelector.js";export default function InputResourceArray({resource,property,required}){const[array,setArray]=useArray(resource,property.subject);const[err,setErr]=useState(null);function handleAdd(){array.push(null);const newArray=array;setArray(newArray);}function handleRemove(index){array.splice(index,1);const newArray=array;setArray(newArray);}function handleSetSubject(value,handleErr,index){array[index]=value;setArray(array,handleErr);}return/* @__PURE__ */React.createElement(React.Fragment,null,array.map((subject,index)=>/* @__PURE__ */React.createElement(ResourceSelector,{key:`${property.subject}${index}${subject}`,value:subject,setSubject:(set,handleErr)=>handleSetSubject(set,handleErr,index),error:err?.index==index&&err,setError:setErr,classType:property.classType,required,handleRemove:()=>handleRemove(index)})),/* @__PURE__ */React.createElement(ButtonMargin,{subtle:true,type:"button",onClick:handleAdd},"add"),err?.index==void 0&&/* @__PURE__ */React.createElement(ErrMessage,null,err?.message),array==[]&&/* @__PURE__ */React.createElement(ErrMessage,null,"Required"));}

If we look at the unexpected token at 1:935, we get a question mark ?. operator for optional chaining, which is an ES2020 feature. So, I've tried setting the compilation target in compilerOptions in tsconfig.json from es2020 to es6, but to no avail. Also tried setting tsconfig's jsx: "preserve", to react. Also tried this suggested fix. Whenever I use snowpack builder (so disabling @snowpack/plugin-webpack), things work fine. That would mean having a bigger bundle size, but maybe that's the best solution as of now.

joepio commented 3 years ago

Switched to snowpack (using esbuild), which is faster, but not as optimized. Closing for now.