Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error "ReferenceError: Cannot access 'Base' before initialization" when running a next.js webapp locally

This is the full index.tsx file's contents:

import { Base } from '../templates/Base';

const Index = () => <Base />;

export default Index;

I've checked other posts with this error message, but none have been structured like this. I'm not really sure what's causing the error, as Base is imported before being referenced. What would "initialization" of Base look like in this instance?

enter image description here

The Base file:

import { Meta } from '../layout/Meta';
import { AppConfig } from '../utils/AppConfig';
import { Banner } from './Banner';
import { Footer } from './Footer';
import { Hero } from './Hero';
import { List } from './List';
import { Navbar } from './Navbar';
import { VerticalFeatures } from './VerticalFeatures';
// import { Search } from './Search';

const Base = () => (
  <div className="antialiased text-gray-600">
    <Meta title={AppConfig.title} description={AppConfig.description} />
    <Navbar />
    <Hero />
    {/* <Search /> */}
    <List />
    <VerticalFeatures />
    <Banner />
    <Footer />
  </div>
);

export { Base };
like image 420
Andrew Avatar asked Oct 25 '25 08:10

Andrew


1 Answers

It seems that there has been a change in SWC:https://github.com/vercel/next.js/issues/46734

After changing const to function, there were no errors reported.

like image 107
dehong yuan Avatar answered Oct 26 '25 23:10

dehong yuan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!