{"id":109,"date":"2025-10-29T16:05:42","date_gmt":"2025-10-29T16:05:42","guid":{"rendered":"https:\/\/cloudabove.com\/kb\/next-js-module-not-found-when-running-a-next-js-build-in-cpanel\/"},"modified":"2025-10-29T16:05:42","modified_gmt":"2025-10-29T16:05:42","slug":"next-js-module-not-found-when-running-a-next-js-build-in-cpanel","status":"publish","type":"post","link":"https:\/\/cloudabove.com\/help\/next-js-module-not-found-when-running-a-next-js-build-in-cpanel\/","title":{"rendered":"Next.js &#8220;Module not found&#8221; when running a Next.js build in cPanel"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Description<\/h2>\n\n\n\n<p>When running <code>npm run build<\/code>, or <code>next build<\/code>, <code>npm<\/code> returns the error &#8220;Module not found&#8221;. <\/p>\n\n\n\n<p><code>npm ci<\/code> or <code>npm install<\/code> shows that all dependencies or modules are installed. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Path issue<\/h3>\n\n\n\n<p>cPanel&#8217;s virtual environment causes issue with TypeScript&#8217;s path aliases, which can prevent <code>npm build<\/code> from discovering the location of the <code>node_modules<\/code> directory. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Environment issue<\/h3>\n\n\n\n<p>The virtual environment is not referencing the correct <code>node_modules<\/code> directory due to a directory or symlink change, or you&#8217;re not currently in the virtual environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Improve path resolution support<\/h3>\n\n\n\n<p>Update your <code>next.config.mjs<\/code> configuration file to contain the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import path from 'path'\n\n\/** @type {import('next').NextConfig} *\/\nconst nextConfig = {\n  webpack: (config) =&gt; {\n    \/\/ Ensure @ resolves to the project root\n    config.resolve.alias&#091;'@'] = path.resolve('.\/')\n    return config\n  },\n}\n\nexport default nextConfig<\/code><\/pre>\n\n\n\n<p class=\"banner-warning\">\u26a0\ufe0f Ensure you backup your <code>next.config.mjs<\/code> before making the above changes<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Ensure you&#8217;re in the virtual environment<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Close your existing SSH or Terminal session and reconnect. <\/li>\n\n\n\n<li>Navigate to <strong>Setup Node.js App<\/strong> in cPanel, click the <strong>Edit<\/strong> pencil besides the app and <strong>run the command<\/strong> shown in:<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"327\" src=\"https:\/\/kb.cloudabove.com\/wp-content\/uploads\/sites\/4\/2025\/10\/image-4-1024x327.png\" alt=\"\" class=\"wp-image-110\" srcset=\"https:\/\/kb.cloudabove.com\/wp-content\/uploads\/sites\/4\/2025\/10\/image-4-1024x327.png 1024w, https:\/\/kb.cloudabove.com\/wp-content\/uploads\/sites\/4\/2025\/10\/image-4-300x96.png 300w, https:\/\/kb.cloudabove.com\/wp-content\/uploads\/sites\/4\/2025\/10\/image-4-768x245.png 768w, https:\/\/kb.cloudabove.com\/wp-content\/uploads\/sites\/4\/2025\/10\/image-4-770x246.png 770w, https:\/\/kb.cloudabove.com\/wp-content\/uploads\/sites\/4\/2025\/10\/image-4.png 1224w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Reattempt <code>npm build<\/code><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Description When running npm run build, or next build, npm returns the error &#8220;Module not found&#8221;. npm ci or npm install shows that all dependencies or modules are installed. Cause Path issue cPanel&#8217;s virtual environment causes issue with TypeScript&#8217;s path aliases, which can prevent npm build from discovering the location&hellip;<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,7,22],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-advanced-techniques","category-cpanel","category-node-js"],"_links":{"self":[{"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":1,"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":111,"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/posts\/109\/revisions\/111"}],"wp:attachment":[{"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudabove.com\/help\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}