Next.js Discord

Discord Forum

Build failed because of webpack errors

Answered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
I'm using Next.js 14.2.24 on my project. This morning, when I started a build, it unexpectedly failed due to Webpack errors. Has anyone encountered this issue or have any insights on what might be causing it?
Answered by Transvaal lion
Thanks for your response! However, after further investigation, I found that I need to remove the node_modules and package-lock.json, then clear the cache before proceeding.
View full answer

3 Replies

White Ibis
Can you try again after removing full modules and package-lock.json and reinstall?
If not works, plz try with this config:
const nextConfig = {  
  reactStrictMode: true,  
  webpack: (config) => {  
    config.resolve.alias = {  
      ...config.resolve.alias,  
      'react': 'preact/compat',  
      'react-dom': 'preact/compat',  
    };  
    return config;  
  },  
};  

module.exports = nextConfig;
Transvaal lionOP
Thanks for your response! However, after further investigation, I found that I need to remove the node_modules and package-lock.json, then clear the cache before proceeding.
Answer