framework
framework copied to clipboard
`NITRO_PRESET=cloudflare` - `nuxt build` generates code with syntax error
Environment
- Operating System:
Darwin - Node Version:
v16.16.0 - Nuxt Version:
3.0.0-rc.7-27670958.b0bf25c - Package Manager:
[email protected] - Builder:
vite - User Config:
modules,css,content,i18n - Runtime Modules:
@nuxt/[email protected],8n,@nuxt/[email protected],@nuxt/[email protected] - Build Modules:
-
Reproduction
https://github.com/PikachuEXE/nuxt-3-edge
Describe the bug
Following instructions at https://nitro.unjs.io/deploy/providers/cloudflare.html#testing-locally
Running
NITRO_PRESET=cloudflare yarn build
npx miniflare .output/server/index.mjs --site .output/public
Would raise error
Additional context
Part of the genetated code wo={...qr,...Vr,...wo,promises:Ao} seems to be the issue
Logs
(Truncated)
Partial generated code (search for wo=)
lculate(H){const K=H.toString("utf8").match(kr.root);if(K){const H=function(H){const K=H.match(kr.width),Y=H.match(kr.height),J=H.match(kr.viewbox);return{height:Y&&parseLength(Y[2]),viewbox:J&&parseViewbox(J[2]),width:K&&parseLength(K[2])}}(K[0]);if(H.width&&H.height)return function(H){return{height:H.height,width:H.width}}(H);if(H.viewbox)return function(H,K){const Y=K.width/K.height;return H.width?{height:Math.floor(H.width/Y),width:H.width}:H.height?{height:H.height,width:Math.floor(H.height*Y)}:{height:K.height,width:K.width}}(H,H.viewbox)}throw new TypeError("Invalid SVG")}};const Or={validate(H){const K="RIFF"===H.toString("ascii",0,4),Y="WEBP"===H.toString("ascii",8,12),J="VP8"===H.toString("ascii",12,15);return K&&Y&&J},calculate(H){const K=H.toString("ascii",12,16);if(H=H.slice(20,30),"VP8X"===K){const K=H[0],Y=0==(1&K);if(0==(192&K)&&Y)return function(H){return{height:1+H.readUIntLE(7,3),width:1+H.readUIntLE(4,3)}}(H);throw new TypeError("Invalid WebP")}if("VP8 "===K&&47!==H[0])return function(H){return{height:16383&H.readInt16LE(8),width:16383&H.readInt16LE(6)}}(H);const Y=H.toString("hex",3,6);if("VP8L"===K&&"9d012a"!==Y)return function(H){return{height:1+((15&H[4])<<10|H[3]<<2|(192&H[2])>>6),width:1+((63&H[2])<<8|H[1])}}(H);throw new TypeError("Invalid WebP")}},Pr={bmp:nr,cur:or,dds:ir,gif:sr,icns:ur,ico:rr,j2c:cr,jp2:mr,jpg:gr,ktx:yr,png:vr,pnm:Ar,psd:wr,svg:Dr,webp:Or},Nr=Object.keys(Pr),Fr={56:"psd",66:"bmp",68:"dds",71:"gif",73:"tiff",77:"tiff",82:"webp",105:"icns",137:"png",255:"jpg"};function lookup(H,K){const Y=function(H){const K=H[0];if(K in Fr){const Y=Fr[K];if(Pr[Y].validate(H))return Y}return Nr.find((K=>Pr[K].validate(H)))}(H);if(Y&&Y in Pr){const J=Pr[Y].calculate(H,K);if(void 0!==J)return J.type=Y,J.mimeType=(H=>"svg"===H?"image/svg+xml":`image/${H}`)(Y),J}throw new TypeError("unsupported file type: "+Y+" (file: "+K+")")}function imageMeta$1(H){if(Buffer.isBuffer(H))return lookup(H);throw new Error("Input should be buffer!")}const Rr=Object.keys(Pr),Ir=Object.freeze(Object.defineProperty({__proto__:null,imageMeta:imageMeta$1,types:Rr},Symbol.toStringTag,{value:"Module"})),Lr=nn.__createMock__("fs.Dir"),jr=nn.__createMock__("fs.Dirent"),Br=nn.__createMock__("fs.Stats"),Mr=nn.__createMock__("fs.ReadStream"),$r=nn.__createMock__("fs.WriteStream"),Hr=nn.__createMock__("fs.FileReadStream"),Ur=nn.__createMock__("fs.FileWriteStream"),qr=Object.freeze(Object.defineProperty({__proto__:null,Dir:Lr,Dirent:jr,Stats:Br,ReadStream:Mr,WriteStream:$r,FileReadStream:Hr,FileWriteStream:Ur},Symbol.toStringTag,{value:"Module"})),zr=Object.create({UV_FS_SYMLINK_DIR:1,UV_FS_SYMLINK_JUNCTION:2,O_RDONLY:0,O_WRONLY:1,O_RDWR:2,UV_DIRENT_UNKNOWN:0,UV_DIRENT_FILE:1,UV_DIRENT_DIR:2,UV_DIRENT_LINK:3,UV_DIRENT_FIFO:4,UV_DIRENT_SOCKET:5,UV_DIRENT_CHAR:6,UV_DIRENT_BLOCK:7,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,O_CREAT:64,O_EXCL:128,UV_FS_O_FILEMAP:0,O_NOCTTY:256,O_TRUNC:512,O_APPEND:1024,O_DIRECTORY:65536,O_NOATIME:262144,O_NOFOLLOW:131072,O_SYNC:1052672,O_DSYNC:4096,O_DIRECT:16384,O_NONBLOCK:2048,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1,F_OK:0,R_OK:4,W_OK:2,X_OK:1,UV_FS_COPYFILE_EXCL:1,COPYFILE_EXCL:1,UV_FS_COPYFILE_FICLONE:2,COPYFILE_FICLONE:2,UV_FS_COPYFILE_FICLONE_FORCE:4,COPYFILE_FICLONE_FORCE:4}),Vr=Object.freeze(Object.defineProperty({__proto__:null,F_OK:0,R_OK:4,W_OK:2,X_OK:1,constants:zr},Symbol.toStringTag,{value:"Module"})),Gr=notImplemented("fs.access"),Wr=notImplemented("fs.copyFile"),Kr=notImplemented("fs.cp"),Yr=notImplemented("fs.open"),Qr=notImplemented("fs.opendir"),Xr=notImplemented("fs.rename"),Jr=notImplemented("fs.truncate"),Zr=notImplemented("fs.rm"),eo=notImplemented("fs.rmdir"),to=notImplemented("fs.mkdir"),no=notImplemented("fs.readdir"),ro=notImplemented("fs.readlink"),oo=notImplemented("fs.symlink"),io=notImplemented("fs.lstat"),ao=notImplemented("fs.stat"),so=notImplemented("fs.link"),lo=notImplemented("fs.unlink"),uo=notImplemented("fs.chmod"),co=notImplemented("fs.lchmod"),po=notImplemented("fs.lchown"),fo=notImplemented("fs.chown"),ho=notImplemented("fs.utimes"),mo=notImplemented("fs.lutimes"),yo=notImplemented("fs.realpath"),_o=notImplemented("fs.mkdtemp"),vo=notImplemented("fs.writeFile"),bo=notImplemented("fs.appendFile"),Eo=notImplemented("fs.readFile"),Co=notImplemented("fs.watch"),Ao=Object.freeze(Object.defineProperty({__proto__:null,access:Gr,copyFile:Wr,cp:Kr,open:Yr,opendir:Qr,rename:Xr,truncate:Jr,rm:Zr,rmdir:eo,mkdir:to,readdir:no,readlink:ro,symlink:oo,lstat:io,stat:ao,link:so,unlink:lo,chmod:uo,lchmod:co,lchown:po,chown:fo,utimes:ho,lutimes:mo,realpath:yo,mkdtemp:_o,writeFile:vo,appendFile:bo,readFile:Eo,watch:Co},Symbol.toStringTag,{value:"Module"})),wo={...qr,...Vr,...wo,promises:Ao};var To={exports:{}},ko={},So={exports:{}},xo={};function getDefaultWhiteList$1(){var H={"align-content":!1,"align-items":!1,"align-self":!1,"alignment-adjust":!1,"alignment-baseline":!1,all:!1,"anchor-point":!1,animation:!1,"animation-delay":!1,"animation-direction":!1,"animation-duration":!1,"animation-fill-mode":!1,"animation-iteration-count":!1,"animation-name":!1,"animation-play-state":!1,"animation-timing-function":!1,azimuth:!1,"backface-visibility":!1,background:!0,"background-attachment":!0,"background-clip":!0,"background-color":!0,"background-image":!0,"background-origin":!0,"background-position":!0,"background-repeat":!0,"background-size":!0,"baseline-shift":!1,binding:!1,bleed:!1,"bookmark-label":!1,"bookmark-level":!1,"bookmark-state":!1,border:!0,"border-bottom":!0,"border-bottom-color":!0,"border-bottom-left-radius":!0,"border-bottom-right-radius":!0,"border-bottom-style":!0,"border-bottom-width":!0,"border-collapse":!0,"border-color":!0,"border-image":!0,"border-image-outset":!0,"border-image-repeat":!0,"border-image-slice":!0,"border-image-source":!0,"border-image-width":!0,"border-left":!0,"border-left-color":!0,"border-left-style":!0,"border-left-width":!0,"border-radius":!0,"border-right":!0,"border-right-color":!0,"border-right-style":!0,"border-right-width":!0,"border-spacing":!0,"border-style":!0,"border-top":!0,"border-top-color":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-top-style":!0,"border-top-width":!0,"border-width":!0,bottom:!1,"box-decoration-break":!0,"box-shadow":!0,"box-sizing":!0,"box-snap":!0,"box-suppress":!0,"break-after":!0,"break-before":!0,"break-inside":!0,"caption-side":!1,chains:!1,clear:!0,clip:!1,"clip-path":!1,"clip-rule":!1,color:!0,"color-interpolation-filters":!0,"column-count":!1,"column-fill":!1,"column-gap":!1,"column-rule":!1,"column-rule-color":!1,"column-rule-style":!1,"column-rule-width":!1,"column-span":!1,"column-width":!1,columns:!1,contain:!1,content:!1,"counter-increment":!1,"counter-reset":!1,"counter-set":!1,crop:!1,cue:!1,"cue-after":!1,"cue-before":!1,cursor:!1,direction:!1,display:!0,"display-inside":!0,"display-list":!0,"display-outside":!0,"dominant-baseline":!1,elevation:!1,"empty-cells":!1,filter:!1,flex:!1,"flex-basis":!1,"flex-direction":!1,"flex-flow":!1,"flex-grow":!1,"flex-shrink":!1,"flex-wrap":!1,float:!1,"float-offset":!1,"flood-color":!1,"flood-opacity":!1,"flow-from":!1,"flow-into":!1,font:!0,"font-family":!0,"font-feature-settings":!0,"font-kerning":!0,"font-language-override":!0,"font-size":!0,"font-size-adjust":!0,"font-stretch":!0,"font-style":!0,"font-synthesis":!0,"font-variant":!0,"font-variant-alternates":!0,"font-variant-caps":!0,"font-variant-east-asian":!0,"font-variant-ligatures":!0,"font-variant-numeric":!0,"font-variant-position":!0,"font-weight":!0,grid:!1,"grid-area":!1,"grid-auto-columns":!1,"grid-auto-flow":!1,"grid-auto-rows":!1,"grid-column":!1,"grid-column-end":!1,"grid-column-start":!1,"grid-row":!1,"grid-row-end":!1,"grid-row-start":!1,"grid-template":!1,"grid-template-areas":!1,"grid-template-columns":!1,"grid-template-rows":!1,"hanging-punctuation":!1,height:!0,hyphens:!1,icon:!1,"image-orientation":!1,"image-resolution":!1,"ime-mode":!1,"initial-letters":!1,"inline-box-align":!1,"justify-content":!1,"justify-items":!1,"justify-self":!1,left:!1,"letter-spacing":!0,"lighting-color":!0,"line-box-contain":!1,"line-break":!1,"line-grid":!1,"line-height":!1,"line-snap":!1,"line-stacking":!1,"line-stacking-ruby":!1,"line-stacking-shift":!1,"line-stacking-strategy":!1,"list-style":!0,"list-style-image":!0,"list-style-position":!0,"list-style-type":!0,margin:!0,"margin-bottom":!0,"margin-left":!0,"margin-right":!0,"margin-top":!0,"marker-offset":!1,"marker-side":!1,marks:!1,mask:!1,"mask-box":!1,"mask-box-outset":!1,"mask-box-repeat":!1,"mask-box-slice":!1,"mask-box-source":!1,"mask-box-width":!1,"mask-clip":!1,"mask-image":!1,"mask-origin":!1,"mask-position":!1,"mask-repeat":!1,"mask-size":!1,"mask-source-type":!1,"mask-type":!1,"max-height":!0,"max-lines":!1,"max-width":!0,"min-height":!0,"min-width":!0,"move-to":!1,"nav-down":!1,"nav-index":!1,"nav-left":!1,"nav-right":!1,"nav-up":!1,"object-fit":!1,"object-position":!1,opacity:!1,order:!1,orphans:!1,outline:!1,"outline-color":!1,"outline-offset":!1,"outline-style":!1,"outline-width":!1,overflow:!1,"overflow-wrap":!1,"overflow-x":!1,"overflow-y":!1,padding:!0,"padding-bottom":!0,"padding-left":!0,"padding-right":!0,"padding-top":!0,page:!1,"page-break-after":!1,"page-break-before":!1,"page-break-inside":!1,"page-policy":!1,pause:!1,"pause-after":!1,"pause-before":!1,perspective:!1,"perspective-origin":!1,pitch:!1,"pitch-range":!1,"play-during":!1,position:!1,"presentation-level":!1,quotes:!1,"region-fragment":!1,resize:!1,rest:!1,"rest-after":!1,"rest-before":!1,richness:!1,right:!1,rotation:!1,"rotation-point":!1,"ruby-align":!1,"ruby-merge":!1,"ruby-position":!1,"shape-image-threshold":!1,"shape-outside":!1,"shape-margin":!1,size:!1,speak:!1,"speak-as":!1,"speak-header":!1,"speak-numeral":!1,"speak-punctuation":!1,"speech-rate":!1,stress:!1,"string-set":!1,"tab-size":!1,"table-layout"
Error message and backtrace
ReferenceError: Cannot access 'wo' before initialization
at /Users/pikachuexe/projects/web3/cosmos/validator/PikaSer-Cosmos/nuxt-3-edge/node_modules/unenv/runtime/node/fs/index.mjs:12:6
at /Users/pikachuexe/projects/web3/cosmos/validator/PikaSer-Cosmos/nuxt-3-edge/.nuxt/dist/server/_nuxt/error-500.6204d579.js:66:72
at Script.runInContext (node:vm:139:12)
at VMScriptRunner.runAsScript (/Users/pikachuexe/.npm/_npx/46ed1b29b205fa85/node_modules/@miniflare/runner-vm/src/index.ts:25:12)
at VMScriptRunner.run (/Users/pikachuexe/.npm/_npx/46ed1b29b205fa85/node_modules/@miniflare/runner-vm/src/index.ts:84:12)
at EventTarget.#reload (/Users/pikachuexe/.npm/_npx/46ed1b29b205fa85/node_modules/@miniflare/core/src/index.ts:748:42)
at EventTarget.getPlugins (/Users/pikachuexe/.npm/_npx/46ed1b29b205fa85/node_modules/@miniflare/core/src/index.ts:985:5)
at createServer (/Users/pikachuexe/.npm/_npx/46ed1b29b205fa85/node_modules/@miniflare/http-server/src/index.ts:355:19)
at startServer (/Users/pikachuexe/.npm/_npx/46ed1b29b205fa85/node_modules/@miniflare/http-server/src/index.ts:456:18)
at main (/Users/pikachuexe/.npm/_npx/46ed1b29b205fa85/node_modules/miniflare/src/cli.ts:110:7)
Hi dear @PikachuEXE
Checking your reproduction, first I've set a flag in nuxt config to make debugging easier:
nitro: {
minify: false
}
Initially, I spotted an important bug in unenv mocks (https://github.com/unjs/unenv/commit/524bc217cc1709948d25fd0ac9ff978b38367974). unenv is a library that mocks things such as fs that are used for libraries to a version that makes workers work. It is fixed now if you update lockfile.
Now I see another issue related to image module. We cannot deploy it to cloudflare workers because IPX and Sharp (built-in image optimizer) cannot work on workers. I had disabled it for now (such a shame we cannot render pikachu!)
The 3rd issue, is bluebird which seems incompatible with cloudflare workers and used by csvtojson (content module adds it). I will investigate it later on. /cc @farnabaz
Also the i18n package doesn't seem to support nuxt3 https://github.com/nuxt-community/i18n-module/issues/1425 . I couldn't get the reproduction project running on gitpod
It does but with partial features (compared to previous version) only See https://www.pikaser.net/en
Any updates on resolving this?
Hi @thehydrogen Is your issue also happening with content module? As I explained above, Nuxt 3 itself is fine on CF but some modules are not compatible which we are working on it 👍🏼
@pi0 Our issue seems to be stemming from Vuetify, but it's possible other packages are also generating broken code.
I get this syntax error when trying to run with miniflare.
[mf:err] C:\Users\blakebuell\Desktop\Development\Vanillo\vanillo-frontend\.output\server\index.mjs:6
get basename () { return basename; },
^
ReferenceError: Cannot access 'basename' before initialization
at Module.get basename [as basename] (C:\Users\blakebuell\Desktop\Development\Vanillo\vanillo-frontend\.output\server\index.mjs:6:23)
at C:\Users\blakebuell\Desktop\Development\Vanillo\vanillo-frontend\node_modules\unenv\runtime\node\path\index.mjs:3:21
at C:\Users\blakebuell\Desktop\Development\Vanillo\vanillo-frontend\.output\server\index.mjs:65917:3
at Script.runInContext (node:vm:139:12)
at VMScriptRunner.runAsScript (C:\Users\blakebuell\AppData\Local\npm-cache\_npx\46ed1b29b205fa85\node_modules\@miniflare\runner-vm\src\index.ts:25:12)
at VMScriptRunner.run (C:\Users\blakebuell\AppData\Local\npm-cache\_npx\46ed1b29b205fa85\node_modules\@miniflare\runner-vm\src\index.ts:84:12)
at EventTarget.#reload (C:\Users\blakebuell\AppData\Local\npm-cache\_npx\46ed1b29b205fa85\node_modules\@miniflare\core\src\index.ts:775:42)
at EventTarget.getPlugins (C:\Users\blakebuell\AppData\Local\npm-cache\_npx\46ed1b29b205fa85\node_modules\@miniflare\core\src\index.ts:1017:5)
at createServer (C:\Users\blakebuell\AppData\Local\npm-cache\_npx\46ed1b29b205fa85\node_modules\@miniflare\http-server\src\index.ts:361:19)
at startServer (C:\Users\blakebuell\AppData\Local\npm-cache\_npx\46ed1b29b205fa85\node_modules\@miniflare\http-server\src\index.ts:468:18)
Seems to be an issue with unenv?
Edit: This seemed to have been fixed with Nuxt RC10