withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
47.23k stars 2.51k forks source link

Middleware intermittently not working on iOS/ARM #8191

Closed ZeldOcarina closed 1 year ago

ZeldOcarina commented 1 year ago

What version of astro are you using?

latest

Are you using an SSR adapter? If so, which one?

No

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

I have a tried a clean install of Astro with npm create astro@latest but I just cannot get my middleware.ts to run.

I need to pass to components some context data and perform some global transformations on my response data but cannot do that.

What's the expected result?

Middleware running correctly. Not flagging willing to submit a pull request as I would not know where to start from.

Link to Minimal Reproducible Example

https://github.com/ZeldOcarina/astro-middleware-bug

Participation

ematipico commented 1 year ago

I just checked out your repro and I could see the log

Screenshot 2023-08-22 at 17 31 15

If your issue is more specific, please make sure to create a repro for that.

ZeldOcarina commented 1 year ago

image Well I don't see it.. :( I am using npm, may that be a factor?

ZeldOcarina commented 1 year ago

@ematipico I think you closed this a little too hastily.. :(

ematipico commented 1 year ago

Even with npm, I can see the log. It's essential to be able to replicate the issue. And I am using a mac like you.

natemoo-re commented 1 year ago

Here's a StackBlitz repro, which definitely seems to be working.

@ZeldOcarina could you run npx astro info and node --version and share the output?

ZeldOcarina commented 1 year ago

Of course!!

mattiarasulo@Host-006 astro-test % npx astro info

Astro version            v2.10.12
Package manager          npm
Platform                 darwin
Architecture             arm64
Adapter                  Couldn't determine.
Integrations             None or couldn't determine.
node --version
v18.15.0
lilnasy commented 1 year ago

Couldn't reproduce on windows or linux.

ematipico commented 1 year ago

@ZeldOcarina it's possible that your terminal doesn't log for some reason. Why don't you try to use it by doing writing something into context.locals, or something else.

ZeldOcarina commented 1 year ago

Hi! All logs on standard routes etc. work properly. It's only the middleware that is not running at all, it's so weird.. May it be the M1 architecture?

lilnasy commented 1 year ago

Did you check if the middleware gets executed?

ZeldOcarina commented 1 year ago

I did by hardcoding some locals and no locals are being passed down to the components etc..

lilnasy commented 1 year ago

Could you upload the dist folder somewhere, maybe in a branch.

That would at least rule out an astro bug from something about your environment.

ZeldOcarina commented 1 year ago

Of course! I've added the dist folder under the same branch! Builded the app and removed dist from .gitignore. Thanks a lot for your help!

lilnasy commented 1 year ago

Ah, it's a static build. /dist contains only html, css, and js.

It maybe worth adding an adapter (npm run astro add node) to see if you get the issue in the final build (node dist/server/entry.mjs) as well.

ZeldOcarina commented 1 year ago

Ok done! Interesting the middleware is called _empty-middleware.mjs for some reason and it's actually empty! https://github.com/ZeldOcarina/astro-middleware-bug/blob/main/dist/server/_empty-middleware.mjs

lilnasy commented 1 year ago

Ok, I see what you see now — not "Request received!".

Building again myself runs the middleware and logs to the console.

Not sure what the issue is. Best guess: you need to reinstall astro, or node. Run npm and other commands in a container if that doesn't work.

ZeldOcarina commented 1 year ago

That's super weird.. I even tried with Bun and yarn..

ZeldOcarina commented 1 year ago

I can confirm building in a Codespace container is working. I think still this should be investigated as it's a very weird behavior..

lilnasy commented 1 year ago

It's hard to investigate because as far as I can tell, the cause is is somewhere on your system.

ZeldOcarina commented 1 year ago

I will try to open a remote M1 from a service I know and see if I can reproduce there.. it may be something that has to do with the ARM architecture..

ematipico commented 1 year ago

I think the best course of action is creating a thread on discord, in the support channel, and chat with people there.

This seems to be an issue specific to someone machine/environment and unfortunately it's very hard to debug unless you do it yourself from the source code.

I have a M2 and I can't see this issue. Weird.

ZeldOcarina commented 1 year ago

Ha I got it! Bug happens only if I clone the repo on my external SSD, won't happen on my main drive. Do you have an external disk you can try it on @ematipico?

ematipico commented 1 year ago

I don't think there's much we can do. This is something related to your machine and environment, I can't look for an external hard drive 😅

natemoo-re commented 1 year ago

Wow that is very strange! I have no idea what could be causing this problem when running on an external SSD. I agree that there's probably not much we can do, since it seems so environment specific... I tried searching through Vite, Rollup, Node issues but can't seem to find anything similar to this either.

lilnasy commented 1 year ago

There is this one issue: https://github.com/withastro/astro/issues/8164#issuecomment-1686046234.

ZeldOcarina commented 1 year ago

Yeah so far only pnpm has always refused to work on the external SSD but I guess next time I will need to upgrade my Mac for that super expensive Apple storage instead of hacking together an NVME enclosure.. Thanks for your time, closing this for now!

WinnieS0728 commented 1 year ago

same issue here

using mac mini m2 macOS 13.5.2(22G91)

node version v18.16.0 npm version 9.5.1 bun version 1.0.2

package.json :

  "dependencies": {
    "@astrojs/node": "^6.0.0",
    "astro": "^3.1.1"
  }

astro.config :

import { defineConfig } from 'astro/config';

import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({});

also tried node adapter

import { defineConfig } from 'astro/config';

import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
  output: "server",
  adapter: node({
    mode: "standalone"
  })
});

and the result here (all test get same result)

image

i clone your astro-middleware-bug repo and get the same issue.

tried npm and bun both not working

realy wierd.

ematipico commented 1 year ago

It really is. All the similar issues that I've seen so far are around project saved in file system that is different from the one where the OS is saved.

WinnieS0728 commented 1 year ago

thanks for replying.

not working in my macbook pro M1. 😢

both my device doesn't have external drives, only the default built-in SSD.

so in my situation I don't know how to fix it.

maybe it's my personal setting error.

I will post my install detail tomorrow, or borrow a windows OS laptop and try again.

ZeldOcarina commented 1 year ago

Could it be something related to the file system formatting? Maybe the error is in APFS or something like that?

github-actions[bot] commented 1 year ago

Hello @ZeldOcarina. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

ZeldOcarina commented 1 year ago

@lilnasy I think you do have a reproduction repo, let's not be too picky on that.. issue should not be closed..

lilnasy commented 1 year ago

So far I thought the linked repo would reproduce the issue on an external disk. But if someone is encountering the bug without it, there's probably another factor to consider.

Either way, I marked it as need repro because it's not an actionable issue, it's just going to sit here.

ZeldOcarina commented 1 year ago

Ok thanks! :)

WinnieS0728 commented 1 year ago

here is my install detail

image

i get this dependencies in package.json

  "dependencies": {
    "astro": "^3.1.1"
  }

image

import { defineMiddleware } from "astro:middleware";

export const onRequest = defineMiddleware((context,next)=>{
    console.log('middleware');

    return next()
}) 

now i got this issue

image

no 'middleware' but only 'page' in terminal log

seems like my onRequest didn't work 🫠.

did i miss any step or do anything wrong ??

I publish this folder to a github repo.

github repo link

can anyone test if this is my personal issue.

thanks for reading this long post.

glad to get any advice.

lilnasy commented 1 year ago

@WinnieS0728 Pretty sure it's something about your (and ZeldOcarina's) system.

image
WinnieS0728 commented 1 year ago

well i just create a new folder and do

still got same issue.

image

but when i do these same step inside my github folder

and look what i got

image

now thing become SUPER WIERD 🤣

lilnasy commented 1 year ago

@WinnieS0728 Your investigation might be really helpful!

You have traditional chinese characters in the path in the first case where you encounter the issue.

Could you post a screenshot where you run the pwd command in both cases?

And see if adding a chinese character to the GitHub directory name breaks it as well.

WinnieS0728 commented 1 year ago

chinese characters new folder

pwd /Users/winnie.chang/Desktop/未命名檔案夾

result image

english characters new folder

pwd /Users/winnie.chang/Desktop/new folder

result image

chinese characters new folder in github folder

pwd /Users/winnie.chang/Documents/GitHub/未命名檔案夾

result image

english characters new folder in github folder

pwd /Users/winnie.chang/Documents/GitHub/new folder in github

result image

direct inside github folder

pwd /Users/winnie.chang/Documents/GitHub

result image

seems like only work direct inside github folder

lilnasy commented 1 year ago

english characters new folder in github folder pwd /Users/winnie.chang/Documents/GitHub/new folder in github

Could you remove spaces from this folder. Maybe /Users/winnie.chang/Documents/GitHub/new/.

WinnieS0728 commented 1 year ago

new folder without space in github folder

pwd /Users/winnie.chang/Documents/GitHub/new

result image

new folder without space

pwd /Users/winnie.chang/Desktop/newFolder

result image

i think you just resolve the issue 🥳.

lilnasy commented 1 year ago

@ZeldOcarina Is there a space in the full path in your project?

lilnasy commented 1 year ago

I can reproduce the issue on linux. middleware-demo -> "middleware demo" (with space)

image
WinnieS0728 commented 1 year ago

so i think maybe is not personal issue ?

I don't know about detail, but I'm guessing is something like astro compiler detect folder name when build running env can't read space or chinese ?

lilnasy commented 1 year ago

@WinnieS0728 The fix in #8614 should work for chinese characters as well.

WinnieS0728 commented 1 year ago

how about the space.

in my case i typed space almost 80% of my project if name have more than 1 words.

the chinese characters '未命名檔案夾' is means 'unnamed folder', and it's the default name when create a new folder in my mac.

i almost never use chinese characters in my projects.

lilnasy commented 1 year ago

Both spaces and non-english characters are fixed.

WinnieS0728 commented 1 year ago

Thank you so so so much.

I search this issue almost a day around google, youtube and even Bing AI.

no one have same issue 🫠.

thanks for your help.

lilnasy commented 1 year ago

Thank you, you're the one who figured what the problem even is! Fixing is the easy part.

ZeldOcarina commented 1 year ago

whoo whoo thanks a bunch @lilnasy @WinnieS0728 ! Yes there was some blank spaces in my OS. Sorry if the issue name was misleading, we made it!