Fermain / -mollify

9 stars 9 forks source link

fixed build error - top-level await #210

Closed StianSto closed 9 months ago

StianSto commented 9 months ago

i had a sneaking suspicion this was my error 😳

there was a "toLocaleLowerCase" in +layout that did not work. should have been toLowerCase(). i also added optional chaining in case type is not defined on entity. while in rome, i refactored the code a tiny bit.

while on the subject there are two other instances of toLocaleLowerCase(). cli/src/actions/entity/list.ts:23:49 lms/src/lib/components/reader/Reader.svelte:44:51

are they done on purpose or is it the same case of autocomplete as i had? i haven't encountered an error here though so maybe it doesn't matter

StianSto commented 9 months ago

well i tested again with toLocaleLowerCase and suddenly that is fine, but lowerCase makes more sense anyways. the actual issue was a toLowerCase() on a potential undefined from entity.type. i dont have the content that Oliver used so i havnt tested with that yet, but it would probably be wise to test this extensively with that first before moving on :)

Fermain commented 9 months ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase

Fermain commented 9 months ago

I still get the same error, although I think I know where it's from:

error during build:
Error: Transform failed with 2 errors:
_app/immutable/chunks/courseProgress.!~{01M}~.js:506:26: ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
_app/immutable/chunks/courseProgress.!~{01M}~.js:535:25: ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
    at failureErrorWithLog (/Users/oliver/Repos/Noroff/Content/-mollify/node_modules/esbuild/lib/main.js:1636:15)
    at /Users/oliver/Repos/Noroff/Content/-mollify/node_modules/esbuild/lib/main.js:837:29
    at responseCallbacks.<computed> (/Users/oliver/Repos/Noroff/Content/-mollify/node_modules/esbuild/lib/main.js:697:9)
    at handleIncomingPacket (/Users/oliver/Repos/Noroff/Content/-mollify/node_modules/esbuild/lib/main.js:752:9)
    at Socket.readFromStdout (/Users/oliver/Repos/Noroff/Content/-mollify/node_modules/esbuild/lib/main.js:673:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
npm ERR! Lifecycle script `build` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: @mollify/lms@0.3.0 
npm ERR!   at location: /Users/oliver/Repos/Noroff/Content/-mollify/packages/lms 
StianSto commented 9 months ago

finally managed to recreate and fix the error. as Oliver mentioned in issue #211 it was indeed related to the stores so i take full blame on this one 😓.

i made some improvements to how the progress tracking works to get around the async issue, as well as making sure courseRelationMap wont be a problem. i did not get the error when i tested npm run build after this commit, so here's hoping this is all that is needed :D