1

I run this command:

npm run build

And I get this error:

> Build optimization failed: found page without a React Component as default export in 
pages/library/store

And this is my store.tsx:

const store = new Map<string, any>();
export default store;

How can I fix it?

user3612383
  • 88
  • 2
  • 10
  • 2
    The default export from that file is a Map, which is indeed not a React component. Also it doesn't contain any JSX, so doesn't need to be a .tsx file. – jonrsharpe Apr 09 '22 at 15:40
  • @jonrsharpe thanks. so, I have to change this file to .js? – user3612383 Apr 09 '22 at 15:41
  • It does have _types_, so can't be a .js file. – jonrsharpe Apr 09 '22 at 15:42
  • @user3612383 Take a look at here, seems you can get some help in there :) https://github.com/vercel/next.js/issues/7094 – Ali.Ghodrat Apr 09 '22 at 15:43
  • I use this file for store my variable. So, how can I fix it? – user3612383 Apr 09 '22 at 15:43
  • @user3612383 I just updated the link, take another look please, cheers. – Ali.Ghodrat Apr 09 '22 at 15:45
  • @Ali.Ghodrat this link could not help me! – user3612383 Apr 09 '22 at 15:50
  • 1
    @user3612383 no problem, just another link on GitHub, hope this one helps: https://github.com/vercel/next.js/issues/9042 and this one: https://github.com/vercel/next.js/pull/9045/files#diff-3db9a9059285308854a7a947b817fc5d – Ali.Ghodrat Apr 09 '22 at 15:57
  • 3
    Nextjs expects anything exported from the `/pages` directory to be a React component. You need to move this code outside of `/pages`. This post discusses nextjs project structure: https://dev.to/vadorequest/a-2021-guide-about-structuring-your-next-js-project-in-a-flexible-and-efficient-way-472 – spatialaustin Apr 09 '22 at 15:58

0 Answers0