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 14.2.4: SyntaxError: Unexpected token '<' #29685

Open
PabloGracia opened this issue Jun 16, 2024 · 2 comments
Open

NextJS 14.2.4: SyntaxError: Unexpected token '<' #29685

PabloGracia opened this issue Jun 16, 2024 · 2 comments
Labels
stage: awaiting response Potential fix was proposed; awaiting response stale no activity on this issue for a long period

Comments

@PabloGracia
Copy link

Current behavior

I'm following the step by step guide on how to use Cypress and NextJS from Vercel's documentation. As recommended, I run Cypress against production code, so I run bun run build && bun run start before running bun run cypress:open. These scrips are defined in package.json as:

"scripts": {
    "build": "next build",
    "start": "next start",
    "cypress:open": "cypress open"
  },

The issue is that when I run the Cypress test, they fail with the error in the title, and I'm at loss at why that might be. In some similar threads I've seen that this could be due to the fact I'm running Cypress tests against .tsx code, but as I'm running them against production code, this shouldn't be the case.

Checking the browser console I see the following, but it doesn't help me much to understand why this "plug-and-play" test is failing:
image

Has anybody run on this in the past and/or know how to troubleshoot it?

Desired behavior

Ideally, this test should work right out of the box, as I'm not testing anything complex, but rather a very simple example.

Test code to reproduce

I'm running the same code as provided in the NextJS example I linked above:

// app/page.tsx

import Link from "next/link";

export default function Page() {
  return (
    <div>
      <h1>Home</h1>
      <Link href="/about">About</Link>
    </div>
  );
}
// app/about/page.tsx
import Link from "next/link";

export default function Page() {
  return (
    <div>
      <h1>About</h1>
      <Link href="/">Home</Link>
    </div>
  );
}
// cypress/e2e/app.cy.js
describe("Navigation", () => {
  it("should navigate to the about page", () => {
    // Start from the index page
    cy.visit("http://localhost:3000/");

    // Find a link with an href attribute containing "about" and click it
    cy.get('a[href="about"]').click();

    // The new url should include "/about"
    cy.url().should("include", "/about");

    // The new page should contain an h1 with "About"
    cy.get("h1").contains("About");
  });
});

Cypress Version

13.11.0

Node version

20.10.0

Operating System

macOS 14.1.1

Debug Logs

No response

Other

No response

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Jun 19, 2024

@PabloGracia

I checked with https://nextjs.org/docs/app/building-your-application/testing/cypress#quickstart and I didn't see any problem running the simple Cypress test spec. I am however not running under macOS.

I noticed that you are using Bun. I don't think this is the cause of your issue, however Cypress doesn't support Bun as package manager. Like for Vercel: npm, Yarn and pnpm are the package managers listed by Cypress in its documentation.

Bun as a replacement for Node.js does not work. Cypress specifies Node.js as prerequisite.

If you believe that you have found a bug in Cypress when it is running in a supported configuration, then, if you can provide a full reproducible example, for instance by forking https://github.com/cypress-io/cypress-test-tiny, somebody can take a look.

You might also like to join the Cypress technical community on Discord

Discord chat (click on button)

@jennifer-shehane jennifer-shehane added the stage: awaiting response Potential fix was proposed; awaiting response label Jun 24, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: awaiting response Potential fix was proposed; awaiting response stale no activity on this issue for a long period
Projects
None yet
Development

No branches or pull requests

4 participants