how to repair: npm run build build next build ▲ Next.js 14.1.0 ✓ Linting and checking…
- User
how to repair: npm run build
build next build
▲ Next.js 14.1.0
✓ Linting and checking validity of types
Creating an optimized production build ... ✓ Compiled successfully ✓ Collecting page data
Generating static pages (0/5) [= ]TypeError: Class constructor a cannot be invoked without 'new' at Wc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:44) at Zc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:253) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89) at Zc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:481) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89) at Zc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:481) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89) at $c (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98) at bd (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:77:404) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:217)Error occurred prerendering page "/lib/SceneInit". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Class constructor a cannot be invoked without 'new'
at Wc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:44) at Zc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:253) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89) at Zc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:481) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89) at Zc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:481) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89) at c (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98) at bd (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:77:404) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:217)Error occurred prerendering page "/lib/SnakeGame". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Class constructor a cannot be invoked without 'new'
at Wc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:44) at Zc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:253) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89) at Zc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:481) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89) at Zc (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:481) at Z (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89) at $c (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98) at bd (C:\Users\VICE\Documents\three-js-games-main\09-snake\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:77:404) ✓ Generating static pages (5/5)Export encountered errors on following paths: /lib/SceneInit /lib/SnakeGame
- Assistant
The error you're encountering is related to using ES6 classes with an environment or tools that do not fully support ES6 class syntax or require a different instantiation method.
The error
TypeError: Class constructor a cannot be invoked without 'new'often happens when you attempt to call a class as a function or if the class is transpiled in a way that prevents it from being called withnew.Here are some steps to troubleshoot the issue:
-
Check Babel Configuration: If you're using Babel, make sure your configuration supports ES6 classes correctly. For instance,
@babel/preset-envshould be configured properly, and you might need the@babel/plugin-transform-classesplugin if you're targeting older environments. -
Review Class Instantiation: Look at the code where
ais defined and any other parts of your code where theaclass is instantiated. Ensure that you're always usingnewto create instances of that class. -
Third-Party Libraries: Sometimes issues arise from third-party libraries that are not transpiled correctly for the target environment. Make sure the dependencies in your project are up-to-date and compiled to the correct JavaScript version.
-
Next.js Version: Since you're using Next.js, make sure you're on a version that supports your codebase. Sometimes, updating (or in some cases, downgrading) to a compatible version can solve these issues.
-
Transpile Node Modules: By default, Next.js does not transpile files inside
node_modules. If the issue is being caused by a third-party library, you may need to customize your Next.js configuration to transpile that particular module. This is done using thenext-transpile-modulespackage or custom Babel settings. -
Source Code Review: Review the components mentioned in the error message (
/lib/SceneInitand/lib/SnakeGame). Ensure they are exporting classes correctly and are not unintentionally invoking classes withoutnew.
If you want to manually adjust your Babel configuration to ensure compatibility, you might add or adjust settings for
preset-envandplugin-transform-classesin your.babelrcorbabel.config.jsfile like so:{ "presets": [ ["@babel/preset-env", { "targets": { // specify targets here (e.g., browsers, Node.js versions) } }] ], "plugins": [ ["@babel/plugin-transform-classes", { "loose": true // or false depending on your needs }] ] }Since this error is displayed during static generation, meaning SSR (Server-Side Rendering) specifically, ensure that any client-side code that is not compatible with SSR is either dynamically imported with the
{ ssr: false }option or guarded appropriately within component lifecycle methods meant for the browser environment (likecomponentDidMountin class components oruseEffectwith an empty dependency array in functional components).Finally, if you are unable to resolve the issue through configuration changes and version updates, you might need to refactor the code causing the issue to adopt a different pattern that does not rely on the problematic class construction.
If these guidance steps don't resolve the issue, please provide additional code context or configurations for more targeted help.
-