Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pages contains process.env.NODE_ENV !== 'production' report 404 error #419

Closed
3 tasks done
Alanscut opened this issue Oct 15, 2021 · 11 comments
Closed
3 tasks done
Labels
bug Something isn't working build Related to the build system
Milestone

Comments

@Alanscut
Copy link

Describe the bug

any page which contains process.env.NODE_ENV !== 'production', it will report 404 error

Reproduction

step 1: clone https://github.com/Alanscut/vitepress-demo

step 2: run the project

step 3: visit the page
image

Expected behavior

could visit the page normally, the page will show:
image

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
    Memory: 7.05 GB / 15.90 GB
  Binaries:
    Node: 12.22.5 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.11 - E:\npm\repo\yarn.CMD
    npm: 7.21.1 - ~\node_modules\.bin\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1023.0), Chromium (94.0.992.50)
    Internet Explorer: 11.0.19041.1202

Additional context

No response

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@Alanscut Alanscut added the bug: pending triage Maybe a bug, waiting for confirmation label Oct 15, 2021
@Alanscut
Copy link
Author

Alanscut commented Oct 16, 2021

This seems to be a bug of https://github.com/vitejs/vite

return import(/*@vite-ignore*/ pageFilePath)

@soetz
Copy link

soetz commented Jan 10, 2022

More precisely, my observations are it’s just process.env.NODE_ENV that makes it break.

I was about to report the same thing so I have another example repo.

@mrcego
Copy link
Contributor

mrcego commented Jan 23, 2022

It could be nice to merge that pull request knowing the issue is resolved on it.

@Akryum
Copy link
Member

Akryum commented Feb 6, 2022

@mrcego
Copy link
Contributor

mrcego commented May 5, 2022

News about this issue?

@kiaking kiaking added bug Something isn't working build Related to the build system and removed bug: pending triage Maybe a bug, waiting for confirmation labels May 24, 2022
@kiaking kiaking added this to To do in v1.0.0-alpha via automation May 24, 2022
@kiaking
Copy link
Member

kiaking commented May 24, 2022

I can reproduce this issue too, but how come current Vite site is working 🤔 It's using 0.22.4 (the latest) I think.

@kiaking
Copy link
Member

kiaking commented May 24, 2022

Oh, OK. Build works. It's failing on Dev mode only. Still we need to fix this.

@kiaking
Copy link
Member

kiaking commented May 24, 2022

Discussion is going on at vitejs/vite#5577 and Vite team is aware of this. Until it gets resolved, please workaround this issue with 👉 vitejs/vite#5577 (comment)

We'll absolutely need to fix this before 1.0.0.

@kiaking kiaking removed this from To do in v1.0.0-alpha May 24, 2022
@kiaking kiaking added this to the v1.0.0 milestone May 27, 2022
@brc-dd brc-dd mentioned this issue Jul 1, 2022
3 tasks
@meteorlxy
Copy link
Member

meteorlxy commented Jul 1, 2022

I found the cause is that process.env.NODE_ENV is being statically replaced even in dev mode. 🤔

So a possible fix is to implement the build mode workaround to dev mode, too. But I'm still curious about why that's happening

@brc-dd
Copy link
Member

brc-dd commented Jul 1, 2022

This looks much better than than that wbr workaround:

`{{ 'process' + '.env.NODE_ENV' }} !== 'production'`

image

(Second one is using wbr tag.)

@meteorlxy
Copy link
Member

meteorlxy commented Jul 1, 2022

I found the reason, vite always statically replaces process.env.NODE_ENV in dev mode (which is not mentioned in the docs):

https://github.com/vitejs/vite/blob/cad27ee8c00bbd5aeeb2be9bfb3eb164c1b77885/packages/vite/src/node/plugins/clientInjections.ts#L57-L64

Now the solution is simple: always "escape" process.env in dev mode. I'll send a PR later.

meteorlxy added a commit to meteorlxy/vitepress that referenced this issue Jul 1, 2022
@brc-dd brc-dd closed this as completed Jul 1, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working build Related to the build system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants