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

NextJS - Failed to start Quarkus #603

Closed
l2c0r3 opened this issue Jan 3, 2024 · 14 comments · Fixed by #607
Closed

NextJS - Failed to start Quarkus #603

l2c0r3 opened this issue Jan 3, 2024 · 14 comments · Fixed by #607
Assignees
Labels
bug Something isn't working
Milestone

Comments

@l2c0r3
Copy link

l2c0r3 commented Jan 3, 2024

Describe the bug

When I create a fresh NextJS application with Quarkus, the DEV mode works without any problems.
The QuarkusTests also work, but I have the following errors with the QuarkusIntegrationTests:

2024-01-03 14:37:07,674 ERROR [io.qua.run.Application] (main) Failed to start application (with profile [prod]): java.lang.RuntimeException: Failed to start quarkus at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source) at io.quarkus.runtime.Application.start(Application.java:101) at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:111) at io.quarkus.runtime.Quarkus.run(Quarkus.java:71) at io.quarkus.runtime.Quarkus.run(Quarkus.java:44) at io.quarkus.runtime.Quarkus.run(Quarkus.java:124) at io.quarkus.runner.GeneratedMain.main(Unknown Source) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:61) at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:32) Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48) at java.base/java.lang.String.charAt(String.java:1512) at io.vertx.ext.web.handler.impl.StaticHandlerImpl.setIndexPage(StaticHandlerImpl.java:635) at io.quarkiverse.quinoa.QuinoaUIResourceHandler.createStaticHandler(QuinoaUIResourceHandler.java:67) at io.quarkiverse.quinoa.QuinoaUIResourceHandler.<init>(QuinoaUIResourceHandler.java:37) at io.quarkiverse.quinoa.QuinoaRecorder.quinoaHandler(QuinoaRecorder.java:41) at io.quarkus.deployment.steps.QuinoaProcessor$runtimeInit397778252.deploy_0(Unknown Source) at io.quarkus.deployment.steps.QuinoaProcessor$runtimeInit397778252.deploy(Unknown Source) ... 13 more

Package.json:

{ "name": "lcm-webui", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "react": "^18", "react-dom": "^18", "next": "14.0.4" }, "devDependencies": { "typescript": "^5", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "autoprefixer": "^10.0.1", "postcss": "^8", "tailwindcss": "^3.3.0", "eslint": "^8", "eslint-config-next": "14.0.4" } }

next.config.js

const nextConfig = { output: 'export', } module.exports = nextConfig

Quinoa version

2.3.1

Quarkus version

3.6.4

Build / Runtime

Next.js

Package Manager

NPM

@melloware
Copy link
Contributor

@shivam-sharma7 didn't you just work with a NextJS project? I know I had it working last year with a NextJS project using NextJS 12.

@shivam-sharma7
Copy link
Member

@melloware Not yet, busy with Horreum and seems issue is not related with next.js config @ia3andy must know

@melloware
Copy link
Contributor

@l2c0r3 can you put together a small reproducer using a simple nextjs app showing the issue?

@melloware melloware added the needs triage Issue needs triaging label Jan 3, 2024
@l2c0r3
Copy link
Author

l2c0r3 commented Jan 3, 2024

@melloware okay, I will do it tomorrow

@melloware melloware added bug Something isn't working and removed needs triage Issue needs triaging labels Jan 3, 2024
@melloware
Copy link
Contributor

Confirmed! Here is the reproducer:

nextjs-project.zip

I get the same error as you.

@l2c0r3
Copy link
Author

l2c0r3 commented Jan 4, 2024

With NextJS version 13.5.6 I have noticed the same thing: DEV mode works but the QuarkusIntegrationTests throws the same error as mentioned.

web-ui.zip

@melloware
Copy link
Contributor

@l2c0r3 found a workaround Juts add this to your application.properties.

quarkus.quinoa.dev-server.index-page=/index.html

That makes the PROD mode work.

@ia3andy I htink there is something wrong with NextFramework.java and this block of code that is making the index empty "" in PRD mode thus causing the Vert.X error above.

        return new QuinoaConfigDelegate(super.override(delegate, packageJson, detectedDevScript, isCustomized)) {

            @Override
            public DevServerConfig devServer() {
                return new DevServerConfigDelegate(super.devServer()) {
                    @Override
                    public Optional<String> indexPage() {
                        // In Dev mode Next.js serves everything out of root "/" but in PRD mode it is the
                        // normal "/index.html".
                        return Optional.of(super.indexPage().orElse("/"));
                    }
                };
            }
        };

@melloware melloware added this to the 2.3.2 milestone Jan 4, 2024
@l2c0r3
Copy link
Author

l2c0r3 commented Jan 4, 2024

Many thanks for the quick answers and analyse @melloware!

Unfortunately, the workaround only works to a limited extent:
The QuarkusIntegrationTests are now running, but the DEV mode no longer works as expected: When I call localhost:8080 it responds now with a status code 404, and not with the nextjs page as before.

I have noticed this with my project as well as your reproducer.

@melloware
Copy link
Contributor

Yep I was just trying to get your past your prd mode issue. The real issue is a bug in nextframework.java overriding the static page to "".

@l2c0r3
Copy link
Author

l2c0r3 commented Jan 4, 2024

Ah I understand. Many thanks to you

@melloware
Copy link
Contributor

Also created #606 which can use the same reproducer from this ticket.

@ia3andy
Copy link
Collaborator

ia3andy commented Jan 5, 2024

Thanks for reporting this @l2c0r3, the error you've catched is just the tip of the iceberg as this could affect any production apps using the configured devserver index page name (instead of the prod one).

To mitigate this issue:

  • if not set (Optional), the dev server index page name is not used, only Next framework automatically overrides it (leading to the production startup failing).
  • If set (this is a new and not very commonly used config) , then currently the dev server index page name would be used in production leading to either a startup failing or a 404 on the index page

@melloware
Copy link
Contributor

@all-contributors add @l2c0r3 for bug

Copy link
Contributor

@melloware

I've put up a pull request to add @l2c0r3! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants