pacocoursey / cmdk

Fast, unstyled command menu React component.
https://cmdk.paco.me
MIT License
9.42k stars 265 forks source link

Webpack Issue #79

Closed ghost closed 6 months ago

ghost commented 1 year ago

I was trying to install it in my project and got this error. Anyone knows how should I resolve it ?

image

`ERROR in ./node_modules/cmdk/dist/index.mjs 1:1916 Module parse failed: Unexpected token (1:1916) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

importas C from"@radix-ui/react-dialog";importas t from"react";import le from"command-score";var ue='[cmdk-list-sizer=""]',M='[cmdk-group=""]',N='[cmdk-group-items=""]',de='[cmdk-group-heading=""]',ee='[cmdk-item=""]',Z=${ee}:not([aria-disabled="true"]),z="cmdk-item-select",S="data-value",fe=(n,i)=>le(n,i),te=t.createContext(void 0),k=()=>t.useContext(te),re=t.createContext(void 0),U=()=>t.useContext(re),ne=t.createContext(void 0),oe=t.forwardRef((n,i)=>{let r=t.useRef(null),o=x(()=>({search:"",value:"",filtered:{count:0,items:new Map,groups:new Set}})),u=x(()=>new Set),l=x(()=>new Map),g=x(()=>new Map),f=x(()=>new Set),d=ie(n),{label:b,children:E,value:v,onValueChange:w,filter:O,shouldFilter:ae,...D}=n,F=t.useId(),p=t.useId(),A=t.useId(),y=ye();L(()=>{if(v!==void 0){let e=v.trim().toLowerCase();o.current.value=e,y(6,W),h.emit()}},[v]);let h=t.useMemo(()=>({subscribe:e=>(f.current.add(e),()=>f.current.delete(e)),snapshot:()=>o.current,setState:(e,c,a)=>{var s,m,R;if(!Object.is(o.current[e],c)){if(o.current[e]=c,e==="search")j(),G(),y(1,V);else if(e==="value")if(((s=d.current)==null?void 0:s.value)!==void 0){(R=(m=d.current).onValueChange)==null||R.call(m,c);return}else a||y(5,W);h.emit()}},emit:()=>{f.current.forEach(e=>e())}}),[]),K=t.useMemo(()=>({value:(e,c)=>{c!==g.current.get(e)&&(g.current.set(e,c),o.current.filtered.items.set(e,B(c)),y(2,()=>{G(),h.emit()}))},item:(e,c)=>(u.current.add(e),c&&(l.current.has(c)?l.current.get(c).add(e):l.current.set(c,new Set([e]))),y(3,()=>{j(),G(),o.current.value||V(),h.emit()}),()=>{g.current.delete(e),u.current.delete(e),o.current.filtered.items.delete(e),y(4,()=>{j(),V(),h.emit()})}),group:e=>(l.current.has(e)||l.current.set(e,new Set),()=>{g.current.delete(e),l.current.delete(e)}),filter:()=>d.current.shouldFilter,label:b||n["aria-label"],listId:F,inputId:A,labelId:p}),[]);function B(e){var a;let c=((a=d.current)==null?void 0:a.filter)??fe;return e?c(e,o.current.search):0}function G(){if(!r.current||!o.current.search||d.current.shouldFilter===!1)return;let e=o.current.filtered.items,c=[];o.current.filtered.groups.forEach(s=>{let m=l.current.get(s),R=0;m.forEach(P=>{let ce=e.get(P);R=Math.max(ce,R)}),c.push([s,R])});let a=r.current.querySelector(ue);I().sort((s,m)=>{let R=s.getAttribute(S),P=m.getAttribute(S);return(e.get(P)??0)-(e.get(R)??0)}).forEach(s=>{let m=s.closest(N);m?m.appendChild(s.parentElement===m?s:s.closest(${N} > *)):a.appendChild(s.parentElement===a?s:s.closest(${N} > *))}),c.sort((s,m)=>m[1]-s[1]).forEach(s=>{let m=r.current.querySelector(${M}[${S}="${s[0]}"]);m==null||m.parentElement.appendChild(m)})}function V(){let e=I().find(a=>!a.ari`

hocgin commented 1 year ago

I have the same problem.

arnaudmanaranche commented 1 year ago

I had the same problem with a Storybook project (webpack v4). Migrate to webpack v5 solves this error.