question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next.js 13 with app folder

See original GitHub issue

I’m trying new app folder which is in beta now since Next.js 13.

But using the app folder, I have an error message that I don’t have in pages folder.

I have pushed a minimal repos for testing purpose: https://github.com/srod/nextjs-13-tremor

git clone https://github.com/srod/nextjs-13-tremor.git
cd nextjs-13-tremor
npm install && npm run dev

Access example page: http://localhost:3000/example

error - (sc_server)/node_modules/@tremor/react/dist/cjs/index.js (6:41848) @ eval
error - TypeError: Super expression must either be null or a function
    at eval (webpack-internal:///(sc_server)/./node_modules/@tremor/react/dist/cjs/index.js:1884:57)
    at eval (webpack-internal:///(sc_server)/./node_modules/@tremor/react/dist/cjs/index.js:1892:6)
    at eval (webpack-internal:///(sc_server)/./node_modules/@tremor/react/dist/cjs/index.js:1952:2)
    at Object.(sc_server)/./node_modules/@tremor/react/dist/cjs/index.js (/Users/rodolphe/Downloads/nextjs-13-tremor/.next/server/app/example/page.js:251:1)
    at __webpack_require__ (/Users/rodolphe/Downloads/nextjs-13-tremor/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///(sc_server)/./app/example/page.tsx:6:71)
    at Object.(sc_server)/./app/example/page.tsx (/Users/rodolphe/Downloads/nextjs-13-tremor/.next/server/app/example/page.js:229:1)
    at __webpack_require__ (/Users/rodolphe/Downloads/nextjs-13-tremor/.next/server/webpack-runtime.js:33:42)
    at Object.page (webpack-internal:///(sc_server)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fexample%2Fpage&appPaths=%2Fexample%2Fpage&pagePath=private-next-app-dir%2Fexample%2Fpage.tsx&appDir=%2FUsers%2Frodolphe%2FDownloads%2Fnextjs-13-tremor%2Fapp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=%2FUsers%2Frodolphe%2FDownloads%2Fnextjs-13-tremor&isDev=true&tsconfigPath=tsconfig.json!:22:124)
    at collectGenerateParams (/Users/rodolphe/Downloads/nextjs-13-tremor/node_modules/next/dist/build/utils.js:710:194) {
  type: 'TypeError',
  page: '/example'
}
null

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mariusflorescucommented, Oct 29, 2022

hi @srod,

When using components that are interactivity, in Next 13, I would suggest creating another file (a wrapper of the component that you want to display), which will be rendered only on the client. The default behavior of Next 13 is server-first, relying on RSC.


Because it’s working by adding ‘use client’; at the top of app/example/page.tsx.

Adding "use client" at the top of page.tsx will make the entire page be client rendered.


How to make it work

Let’s say you want to add an Area Chart to any of your pages.

Let’s create a component called AreaChartComponent.tsx (this is only a wrapper, where we specify that it needs to be client rendered).

"use client";

import { Card, Title, AreaChart } from "@tremor/react";

const chartdata = [
  {
    date: "Jan 22",
    SemiAnalysis: 2890,
    "The Pragmatic Engineer": 2338,
  },
  {
    date: "Feb 22",
    SemiAnalysis: 2756,
    "The Pragmatic Engineer": 2103,
  },
  {
    date: "Mar 22",
    SemiAnalysis: 3322,
    "The Pragmatic Engineer": 2194,
  },
  {
    date: "Apr 22",
    SemiAnalysis: 3470,
    "The Pragmatic Engineer": 2108,
  },
  {
    date: "May 22",
    SemiAnalysis: 3475,
    "The Pragmatic Engineer": 1812,
  },
  {
    date: "Jun 22",
    SemiAnalysis: 3129,
    "The Pragmatic Engineer": 1726,
  },
];

const dataFormatter = (number: number) => {
  return "$ " + Intl.NumberFormat("us").format(number).toString();
};

export default function AreaChartComponent() {
  return (
    <Card>
      <Title>Newsletter revenue over time (USD)</Title>
      <AreaChart
        data={chartdata}
        categories={["SemiAnalysis", "The Pragmatic Engineer"]}
        dataKey="date"
        height="h-72"
        colors={["indigo", "cyan"]}
        valueFormatter={dataFormatter}
        marginTop="mt-4"
      />
    </Card>
  );
}

Now, in your app/example/page.tsx, let’s remove the "use client", and just import our wrapper component.

/* other imports */
import Component from "./component";

export default function Page() {
  return (
    <div>
      {/* other stuff */}
      <Component />
    </div>
  );
}

2reactions
mariusflorescucommented, Oct 29, 2022

@mitrotasios About the error message:

error - TypeError: Super expression must either be null or a function

The issue might be related to circular dependencies from d3-interpolate + incorrect usage of client components.

(!) Circular dependencies
node_modules/d3-interpolate/src/value.js -> node_modules/d3-interpolate/src/array.js -> node_modules/d3-interpolate/src/value.js
node_modules/d3-interpolate/src/value.js -> node_modules/d3-interpolate/src/object.js -> node_modules/d3-interpolate/src/value.js

Additionally, I think that the labels could be removed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js 13: Working with the new app directory
Explore the new features introduced in the Next.js 13 app directory, which provide much more flexibility to configure our UI.
Read more >
App Directory Roadmap
Section Feature Supported React 18 Server Components ✓ Default React 18 Client Components ✓ Opt‑in React 18 Shared Components 🏗️
Read more >
How the App Directory Works in Next.js 13
The new app directory is definitely an improvement from the previous pages directory. It includes special files like layout, head, template, ...
Read more >
Next.js 13 App Playground
Explore the new app directory in Next.js 13. ... While you don't need to use the app/ directory when upgrading to Next.js 13,...
Read more >
[Feedback] App Directory in Next.js 13 · Discussion #41745
Next.js 13 introduces the app directory (beta) with new features and conventions. However, upgrading to Next.js 13 does not require using the app...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found