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

Error thrown while building app in Github Actions #1450

Closed
woodcipher opened this issue Jan 20, 2024 · 6 comments
Closed

Error thrown while building app in Github Actions #1450

woodcipher opened this issue Jan 20, 2024 · 6 comments
Labels

Comments

@woodcipher
Copy link

Description

Hello, we recently upgraded to vite-plugin-ssr 0.4.142 (we are hoping to tackle the upgrade to Vike at a later time) and started seeing this error when building our app in Github Actions:

$ cross-env NODE_ENV=ci ts-node ./server
[vite-plugin-ssr][Warning] The vite-plugin-ssr project has been renamed to Vike, see https://vite-plugin-ssr.com/vike
{"level":30,"time":1705779475279,"pid":4709,"hostname":"fv-az343-733","msg":"[startServer]: appEnv: ci isPrimary: true isProductionLike: true"}
{"level":30,"time":1705779475289,"pid":4709,"hostname":"fv-az343-733","msg":"Server running at http://localhost:3000"}

/home/runner/work/jade/jade/node_modules/vite-plugin-ssr/dist/cjs/utils/assertIsNotProductionRuntime.js:40
        (0, assert_js_1.assert)(!env.isVite);
                               ^
Error: [[email protected]][Bug] You stumbled upon a bug in vite-plugin-ssr's source code. Go to https://github.com/brillout/vite-plugin-ssr/issues/new and copy-paste this error; a maintainer will fix the bug (usually under 24 hours).
    at assertEnv (/home/runner/work/jade/jade/node_modules/vite-plugin-ssr/dist/cjs/utils/assertIsNotProductionRuntime.js:40:32)
    at renderPage (/home/runner/work/jade/jade/node_modules/vite-plugin-ssr/dist/cjs/node/runtime/renderPage.js:41:30)
    at /home/runner/work/jade/jade/server/index.ts:179:59
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/route.js:144:13)
    at Route.dispatch (/home/runner/work/jade/jade/node_modules/express/lib/router/route.js:114:3)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:284:15
    at param (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:365:14)
    at param (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:376:14)
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:421:3)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at /home/runner/work/jade/jade/node_modules/sirv/build.js:176:28
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at cacheHeaders (/home/runner/work/jade/jade/server/middleware/cache_response_headers.ts:14:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at XFrameOptionsHeader (/home/runner/work/jade/jade/server/middleware/owasp_headers.ts:11:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at compression (/home/runner/work/jade/jade/node_modules/compression/index.js:220:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at loggingMiddleware (/home/runner/work/jade/jade/node_modules/pino-http/logger.js:202:7)
    at result (/home/runner/work/jade/jade/node_modules/pino-http/logger.js:89:12)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at expressInit (/home/runner/work/jade/jade/node_modules/express/lib/middleware/init.js:40:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at query (/home/runner/work/jade/jade/node_modules/express/lib/middleware/query.js:45:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at Function.handle (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:175:3)
    at Function.handle (/home/runner/work/jade/jade/node_modules/express/lib/application.js:181:10)
    at Server.app (/home/runner/work/jade/jade/node_modules/express/lib/express.js:39:9)
    at Server.emit (node:events:514:28)
    at Server.emit (node:domain:488:12)
    at parserOnIncoming (node:_http_server:1143:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 52.

Does anyone recognize this as a common issue? Any guidance would be greatly appreciated!

@brillout
Copy link
Member

This is likely a duplicate of a previous issue that was already fixed.

Update to the latest version; I'll re-open if you still get this.

@brillout brillout closed this as not planned Won't fix, can't repro, duplicate, stale Jan 20, 2024
@woodcipher
Copy link
Author

Thank you for the ultra-quick response. I just tried re-running with the latest version of Vike and got what looks to be the same error:

$ cross-env NODE_ENV=ci ts-node ./server
{"level":30,"time":1705780914475,"pid":4794,"hostname":"fv-az241-772","msg":"[startServer]: appEnv: ci isPrimary: true isProductionLike: true"}
{"level":30,"time":1705780914487,"pid":4794,"hostname":"fv-az241-772","msg":"Server running at http://localhost:3000"}

/home/runner/work/jade/jade/node_modules/vike/dist/cjs/utils/assertIsNotProductionRuntime.js:40
        (0, assert_js_1.assert)(!env.isVite);
                               ^
Error: [[email protected]][Bug] You stumbled upon a bug in Vike's source code. Go to https://github.com/vikejs/vike/issues/new and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).
    at assertEnv (/home/runner/work/jade/jade/node_modules/vike/dist/cjs/utils/assertIsNotProductionRuntime.js:40:32)
    at renderPage (/home/runner/work/jade/jade/node_modules/vike/dist/cjs/node/runtime/renderPage.js:41:30)
    at /home/runner/work/jade/jade/server/index.ts:179:59
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/route.js:144:13)
    at Route.dispatch (/home/runner/work/jade/jade/node_modules/express/lib/router/route.js:114:3)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:284:15
    at param (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:365:14)
    at param (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:376:14)
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:421:3)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at /home/runner/work/jade/jade/node_modules/sirv/build.js:176:28
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at cacheHeaders (/home/runner/work/jade/jade/server/middleware/cache_response_headers.ts:14:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at XFrameOptionsHeader (/home/runner/work/jade/jade/server/middleware/owasp_headers.ts:11:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at compression (/home/runner/work/jade/jade/node_modules/compression/index.js:220:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at loggingMiddleware (/home/runner/work/jade/jade/node_modules/pino-http/logger.js:202:7)
    at result (/home/runner/work/jade/jade/node_modules/pino-http/logger.js:89:12)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at expressInit (/home/runner/work/jade/jade/node_modules/express/lib/middleware/init.js:40:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at query (/home/runner/work/jade/jade/node_modules/express/lib/middleware/query.js:45:5)
    at Layer.handle [as handle_request] (/home/runner/work/jade/jade/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:328:13)
    at /home/runner/work/jade/jade/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:346:12)
    at next (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:280:10)
    at Function.handle (/home/runner/work/jade/jade/node_modules/express/lib/router/index.js:175:3)
    at Function.handle (/home/runner/work/jade/jade/node_modules/express/lib/application.js:181:10)
    at Server.app (/home/runner/work/jade/jade/node_modules/express/lib/express.js:39:9)
    at Server.emit (node:events:514:28)
    at Server.emit (node:domain:488:12)
    at parserOnIncoming (node:_http_server:1143:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 52.

@brillout
Copy link
Member

I'm afraid I'll need a reproduction for this. Is that something you can come up with?

Alternatively, I can recommend digging into why the assertion fails. This may be quicker than creating a reproduction (or help creating one).

It's quite an import assert as it ensure you don't load Vite in production (which is important to avoid memory leaks, among others).

@woodcipher
Copy link
Author

woodcipher commented Jan 20, 2024

Thanks again, I really appreciate your recommendation to continue digging into this.

After doing just that, I think I've been able to pinpoint the issue around importing vite when starting our server in production mode.

Here's the relevant bit from our /server/index.ts:

if (process.env.NODE_ENV === 'development') {
  console.log('Development env')
  const vite = await import('vite')
  const viteDevMiddleware = (await vite.createServer(devConfig)).middlewares
  app.use(viteDevMiddleware)
} else {
  console.log('Non-development env')
  const sirv = (await import('sirv')).default
  app.use(sirv(`${root}/dist/client`))
}

When running vite build in Production mode, then running ts-node ./server with NODE_ENV=production, I see the same assertion error that I originally saw earlier today when building the app on Github CI.

What's confusing to me is that I'm seeing the 'Non-development env' console log as expected, and not seeing the 'Development env' log, but vite still seems to be included somehow (and creating + registering the dev server as middleware?). If I remove the above block of code and replace it with simply:

const sirv = (await import('sirv')).default
app.use(sirv(`${root}/dist/client`))

then the assertion error is no longer thrown and the app renders correctly.

Is the vite import somehow being hoisted? Even so, it seems like we'd also need to be creating the Vite dev server and registering it as middleware to cause this issue, but I'm not sure how that can be happening the way the code is currently written.

Sincerely stumped, Allen

@woodcipher
Copy link
Author

Update: Got it!

The devConfig variable in my example above was a top-level import in our /server/index.ts file. Replacing this with the following simpler config prevented the unwanted Vite config object from being used:

const viteDevMiddleware = (await vite.createServer({ server: { middlewareMode: true } })).middlewares

Thank you @brillout again for your help and quick responses!

@brillout
Copy link
Member

Ok neat 👍

I've improved the error message. It should make handling this situation much easier for the user.

Btw. would your company be up for sponsoring? It's make a big difference for us!

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

No branches or pull requests

2 participants