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

does not work with surge out of the box (process.env not defined) (neither vite nor nextjs) #112

Closed
msmyers opened this issue Aug 3, 2022 · 1 comment

Comments

@msmyers
Copy link

msmyers commented Aug 3, 2022

Describe the bug

  • when deploying on surge,
    • the vite build (when viewed on surge) throws an error that "process" is not defined.
    • the next build (when viewed on surge) throws 404 not found.

To Reproduce
Steps to reproduce the behavior:

yarn build && yarn surge

Expected behavior
I expected the website to load.

Screenshots
If applicable, add screenshots to help explain your problem.


Fix:

// see https://vitejs.dev/config/shared-options.html#define
define: {
  'process.env.SOME_ENV': `"${process.env.SOME_ENV}"`
}
// see: https://www.npmjs.com/package/vite-plugin-environment
import { defineConfig } from 'vite'

export default defineConfig({
  define: {
    'process.env.API_KEY': JSON.stringify(process.env.API_KEY),
    'process.env.DEBUG': JSON.stringify(process.env.DEBUG),
  }
})
@ShravanSunder
Copy link
Member

To be fixed in new version.
@msmyers the nextjs version won't be chaned. It doesn't make sense to use nextjs for static build when you can use the vite version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants