HiDeoo / starlight-openapi

Starlight plugin to generate documentation from OpenAPI/Swagger specifications
https://starlight-openapi.vercel.app
MIT License
107 stars 13 forks source link

commonjs--resolver] Missing "./layout/Page.astro" specifier in "@astrojs/starlight" package #5

Closed f4ez closed 11 months ago

f4ez commented 1 year ago

Describe the bug

[commonjs--resolver] Missing "./layout/Page.astro" specifier in "@astrojs/starlight" package error Missing "./layout/Page.astro" specifier in "@astrojs/starlight" package

Code:

21420 | function e(e,n,r){throw new Error(r?No known conditions for "${n}" specifier in "${e}" package:Missing "${n}" specifier in "${e}" package)}function n(n,i,o,f){let s,u,l=r(n,o),c=function(e){let n=new Set(["default",...e.conditions||[]]);return e.unsafe||n.add(e.require?"require":"import"),e.unsafe||n.add(e.browser?"browser":"node"),n}(f||{}),a=i[l];if(void 0===a){let e,n,r,t;for(t in i)n&&t.length<n.length||("/"===t[t.length-1]&&l.startsWith(t)?(u=l.substring(t.length),n=t):t.length>1&&(r=t.indexOf("",1),~r&&(e=RegExp("^"+t.substring(0,r)+"(.)"+t.substring(1+r)).exec(l),e&&e[1]&&(u=e[1],n=t))));a=i[n];}return a||e(n,l),s=t(a,c),s||e(n,l,1),u&&function(e,n){let r,t=0,i=e.length,o=/[*]/g,f=/[/]$/;for(;t<i;t++)e[t]=o.test(r=e[t])?r.replace(o,n):f.test(r)?r+n:r;}(s,u),s}function r(e,n,r){if(e===n||"."===n)return ".";let t=e+"/",i=t.length,o=n.slice(0,i)===t,f=o?n.slice(i):n;return "#"===f[0]?f:o||!r?"./"===f.slice(0,2)?f:"./"+f:f}function t(e,n,r){if(e){if("string"==typeof e)return r&&r.add(e),[e];let i,o;if(Array.isArray(e)){for(o=r||new Set,i=0;i<e.length;i++)t(e[i],n,o);if(!r&&o.size)return [...o]}else for(i in e)if(n.has(i))return t(e[i],n,r)}}function o(e,r,t){let i,o=e.exports;if(o){if("string"==typeof o)o={".":o};else for(i in o){"."!==i[0]&&(o={".":o});break}return n(e.name,o,r||".",t)}}function f(e,r,t){if(e.imports)return n(e.name,e.imports,r,t)} | ^ 21422 | // This file was generated. Do not modify manually! 21423 | var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 81, 2, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 9, 5351, 0, 7, 14, 13835, 9, 87, 9, 39, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4706, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 983, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];

To Reproduce

"dependencies": { "@astrojs/react": "^3.0.1", "@astrojs/starlight": "^0.10.2", "@astrojs/starlight-tailwind": "^2.0.0", "@astrojs/tailwind": "^5.0.0", "@types/react-dom": "^18.0.6", "astro": "^3.1.4", "react": "^18.0.0", "react-dom": "^18.0.0", "sharp": "^0.32.5", "starlight-openapi": "^0.2.0", "tailwindcss": "^3.0.24" }, "devDependencies": { "@types/react": "^18.0.21" }

as I remove starlightOpenAPI() from the config file error will be fixed.

Expected behavior

build successfully

How often does this bug happen?

Every time

System Info

windows chrome

Additional Context

No response

HiDeoo commented 1 year ago

This seems to be a duplicate of https://github.com/HiDeoo/starlight-blog/issues/10#issuecomment-1715384615 which is a Windows specific issue related to some of the Vite shenanigans and fragile APIs used to customize Starlight.

I did not have yet the opportunity to debug this issue on a Windows machine.

Note that when component customisation will land in Starlight and after updating this integration to use this new feature, this should no longer be an issue.

f4ez commented 1 year ago

This seems to be a duplicate of HiDeoo/starlight-blog#10 (comment) which is a Windows specific issue related to some of the Vite shenanigans and fragile APIs used to customize Starlight.

I did not have yet the opportunity to debug this issue on a Windows machine.

Note that when component customisation will land in Starlight and after updating this integration to use this new feature, this should no longer be an issue.

another issue with linux (Ubuntu 22.04) (tested with yarn, npm and pnpm):

nodemodules/.pnpm/starlight-openapi@0.2.0@astrojs+starlight@0.10.2_astro@3.1.4_openapi-types@12.1.3/node_modules/starlight-openapi/components/Route.astro error Invalid second argument for transform! Expected Transformer[] but got object File: /home/x/Desktop/doc/node_modules/ultrahtml/dist/index.js:1:4646 Code:

1 | var R=0,k=1,j=2,X=3,V=4;function U(e,t={},...a){let r={type:1,name:typeof e=="function"?e.name:e,attributes:t||{},children:a.map(n=>typeof n=="string"?{type:2,value:y(String(n))}:n),parent:void 0,loc:[]};return typeof e=="function"&&$(r,e),r}var b=Symbol("Fragment"),D=new Set(["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),x=new Set(["script","style"]),=/([\@.a-z0-9\:-])\s?=?\s?(['"]?)([\s\S]?)\2\s+/gim,o=/(?:<(\/?)([a-zA-Z][a-zA-Z0-9\:-])(?:\s([^>]?))?((?:\s\/)?)>|(<!--)([\s\S]?)(-->)|(<!)([\s\S]*?)(>))/gm;function P(e){let t={},a;if(e)for(.lastIndex=0,e=" "+(e||"")+" ";a=.exec(e);)a[0]!==" "&&(t[a[1]]=a[3]);return t}function w(e){let t=typeof e=="string"?e:e.value,a,r,n,i,l,d,g,h,s,c=[];o.lastIndex=0,r=a={type:0,children:[]};let E=0;function m(){i=t.substring(E,o.lastIndex-n[0].length),i&&r.children.push({type:2,value:i,parent:r})}for(;n=o.exec(t);){if(d=n[5]||n[8],g=n[6]||n[9],h=n[7]||n[10],x.has(r.name)&&n[2]!==r.name){l=o.lastIndex-n[0].length,r.children.length>0&&(r.children[0].value+=n[0]);continue}else if(d==="<!--"){if(l=o.lastIndex-n[0].length,x.has(r.name))continue;s={type:3,value:g,parent:r,loc:[{start:l,end:l+d.length},{start:o.lastIndex-h.length,end:o.lastIndex}]},c.push(s),s.parent.children.push(s)}else if(d==="<!")l=o.lastIndex-n[0].length,s={type:4,value:g,parent:r,loc:[{start:l,end:l+d.length},{start:o.lastIndex-h.length,end:o.lastIndex}]},c.push(s),s.parent.children.push(s);else if(n[1]!=="/")if(m(),x.has(r.name)){E=o.lastIndex,m();continue}else s={type:1,name:n[2]+"",attributes:P(n[3]),parent:r,children:[],loc:[{start:o.lastIndex-n[0].length,end:o.lastIndex}]},c.push(s),s.parent.children.push(s),n[4]&&n[4].indexOf("/")>-1||D.has(s.name)?(s.loc[1]=s.loc[0],s.isSelfClosingTag=!0):r=s;else m(),n[2]+""===r.name?(s=r,r=s.parent,s.loc.push({start:o.lastIndex-n[0].length,end:o.lastIndex}),i=t.substring(s.loc[0].end,s.loc[1].start),s.children.length===0&&s.children.push({type:2,value:i,parent:r})):n[2]+""===c[c.length-1].name&&c[c.length-1].isSelfClosingTag===!0&&(s=c[c.length-1],s.loc.push({start:o.lastIndex-n[0].length,end:o.lastIndex}));E=o.lastIndex}return i=t.slice(E),r.children.push({type:2,value:i,parent:r}),a}var T=class{constructor(t){this.callback=t}async visit(t,a,r){if(await this.callback(t,a,r),Array.isArray(t.children)){let n=[];for(let i=0;i<t.children.length;i++){let l=t.children[i];n.push(this.visit(l,t,i))}await Promise.all(n)}}},O=class{constructor(t){this.callback=t}visit(t,a,r){if(this.callback(t,a,r),Array.isArray(t.children))for(let n=0;n<t.children.length;n++){let i=t.children[n];this.visit(i,t,n)}}},N=Symbol("HTMLString"),S=Symbol("AttrString"),u=Symbol("RenderFn");function p(e,t=[N]){let a={value:e};for(let r of t)Object.defineProperty(a,r,{value:!0,enumerable:!1,writable:!1});return a}function Y(e){return p(e)}function $(e,t){return Object.defineProperty(e,u,{value:t,enumerable:!1}),e}var I={"&":"&","<":"<",">":">"};function y(e){return e.replace(/[&<>]/g,t=>I[t]||t)}function f(e){let t="";for(let[a,r]of Object.entries(e))t+=${a}="${r}";return p(t,[N,S])}function F(e,...t){let a="";for(let r=0;r<e.length;r++){a+=e[r];let n=t[r];a.endsWith("...")&&n&&typeof n=="object"?(a=a.slice(0,-3).trimEnd(),a+=f(n).value):n&&n[S]?(a=a.trimEnd(),a+=n.value):n&&n[N]?a+=n.value:typeof n=="string"?a+=y(n):(n||n===0)&&(a+=String(n))}return p(a)}function H(e,t){return new T(t).visit(e)}function z(e,t){return new O(t).visit(e)}function M(e){if(e.children.length===0){let t=e;for(;t=t.parent;)if(t.name==="svg")return!0}return!1}async function A(e){let{name:t,attributes:a={}}=e,r=await Promise.all(e.children.map(i=>v(i))).then(i=>i.join(""));if(u in e){let i=await eu;return i&&i[N]?i.value:y(String(i))}if(t===b)return r;let n=M(e);return n||D.has(t)?<${e.name}${f(a).value}${n?" /":""}>:<${e.name}${f(a).value}>${r}</${e.name}>}function L(e){let{name:t,attributes:a={}}=e,r=e.children.map(i=>C(i)).join("");if(u in e){let i=eu;return i&&i[N]?i.value:y(String(i))}if(t===b)return r;let n=M(e);return n||D.has(t)?<${e.name}${f(a).value}${n?" /":""}>:<${e.name}${f(a).value}>${r}</${e.name}>}function C(e){switch(e.type){case 0:return e.children.map(t=>C(t)).join("");case 1:return L(e);case 2:return${e.value};case 3:return<!--${e.value}-->;case 4:return<!${e.value}>}}async function v(e){switch(e.type){case 0:return Promise.all(e.children.map(t=>v(t))).then(t=>t.join(""));case 1:return A(e);case 2:return${e.value};case 3:return<!--${e.value}-->;case 4:return<!${e.value}>}}async function B(e,t=[]){if(!Array.isArray(t))throw new Error(Invalid second argument for \transform`! Expected `Transformer[]` but got `${typeof t}`);let r=typeof e=="string"?w(e):e;for(let n of t)r=await n(r);return v(r)}export{X as COMMENT_NODE,V as DOCTYPE_NODE,R as DOCUMENT_NODE,k as ELEMENT_NODE,b as Fragment,u as RenderFn,j as TEXT_NODE,Y as __unsafeHTML,$ as __unsafeRenderFn,f as attrs,U as h,F as html,w as parse,v as render,C as renderSync,B as transform,H as walk,z as walkSync}; ^ Stacktrace: Error: Invalid second argument fortransform! ExpectedTransformer[]but gotobject` at B (file:///home/x/Desktop/doc/node_modules/ultrahtml/dist/index.js:1:4646) at markdown (file:///home/x/Desktop/doc/dist/chunks/pages/Route_be303568.mjs:501:10) at async file:///home/x/Desktop/doc/dist/chunks/pages/Route_be303568.mjs:522:19

 ELIFECYCLE  Command failed with exit code 1.

HiDeoo commented 1 year ago

Indeed, this seems to have workaround the Windows issue.

Altho, I cannot repro the new issue on a fresh install. Would you be able to share a small repro on a GitHub repo or something similar?

f4ez commented 1 year ago

Indeed, this seems to have workaround the Windows issue.

Altho, I cannot repro the new issue on a fresh install. Would you be able to share a small repro on a GitHub repo or something similar?

https://github.com/faeztgh/starlight-openapi-issue-temp

Everything works fine on dev, but when I want to build I get errors. You can see the setup on the above repo. OS: win10 node version: 18.17.1 yarn version: 1.22.19 npm version: 9.6.7 (I tested both yarn and npm) Thanks for making this useful tool :)

HiDeoo commented 1 year ago

Interesting, even in the repository you linked I can not repro any issue after cloning and installing dependencies. Building works fine.

I would assume from the details you shared this is once again Windows related maybe? I guess we would need to wait for me or someone else with access to a Windows machine to debug this or for this integration to be updated to use component customisation when it lands in Starlight.