简体   繁体   English

Next Js 找不到下一个模块

[英]Next Js cannot find module next

I created Next Js project.我创建了 Next Js 项目。 I deployed it to my CPanel.我将它部署到我的 CPanel。 And I created server.js file on directory.我在目录上创建了 server.js 文件。 I called next module as require in server.js.我在 server.js 中将下一个模块称为 require 。 But When I access to my website I catch an error.但是当我访问我的网站时,我发现了一个错误。

internal/modules/cjs/loader.js:638 throw err;内部/模块/cjs/loader.js:638 抛出错误; ^ ^

Error: Cannot find module 'next';错误:找不到模块“下一个”;

This error message.此错误消息。

My server.js code我的 server.js 代码

const { createServer } = require("http");
const { parse } = require("url");
const next = require("next");
const dev = process.env.NODE_ENV !== "production";

const port = !dev ? process.env.PORT : 3000;

// Create the Express-Next App
const app = next({ dev });
const handle = app.getRequestHandler();

app
  .prepare()
  .then(() => {
    createServer((req, res) => {
      const parsedUrl = parse(req.url, true);
      const { pathname, query } = parsedUrl;
      handle(req, res, parsedUrl);
      console.log("pathname", pathname);
    }).listen(port, (err) => {
      if (err) throw err;
      console.log(`> Ready on http://localhost:${port}`);
    });
  })
  .catch((ex) => {
    console.error(ex.stack);
    process.exit(1);
  });

My package json我的 package json

{
  "name": "projectName",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "NODE_ENV=production node server.js"
  },
  "dependencies": {
    "express": "^4.17.1",
    "next": "10.0.6",
    "react": "17.0.1",
    "react-dom": "17.0.1"
  }
}

What should i do?我应该怎么办?

Thank you.谢谢你。 Best regards此致

I've already had problems publishing a next application other than on vercel.除了在 vercel 上发布下一个应用程序时,我已经遇到了问题。 To fix the error I had to create a docker in order to publish the application.要修复错误,我必须创建 docker 才能发布应用程序。 In case someone doesn't answer with a more viable solution, I recommend looking into using a docker.如果有人没有提供更可行的解决方案,我建议考虑使用 docker。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:找不到模块 '/next'、docker、next.js - Error: Cannot find module '/next', docker, next.js Next.js 找不到模块 loader.js - Next.js cannot find module loader.js 错误:在 next.js 中找不到模块“swiper/react” - Error: Cannot find module 'swiper/react' in next.js 下一个 js 应用程序无法运行 react 模块 - Next js application cannot run react module Next.js 脚本错误:找不到模块 '../../webpack-runtime.js' - Next.js Scripts Error: Cannot find module '../../webpack-runtime.js' Vercel 上的部署错误:找不到模块“/vercel/workpath0/.next/server/scripts/build-rss.js” - Deplopyment Error on Vercel: Cannot find module '/vercel/workpath0/.next/server/scripts/build-rss.js' 即使我仅在“getStaticProps()”中使用 fs 代码,也找不到模块“fs/promises” - 下一个 js - Cannot find module 'fs/promises' even when I use the fs code only inside "getStaticProps()" - next js 错误:在 Next 项目上运行 npm run dev 时找不到模块“D:\next\dist\bin\next” - Error: Cannot find module 'D:\next\dist\bin\next' when running npm run dev on a Next project 找不到模块“js” - Cannot find module 'js' 下一个翻译找不到模块'./locales/en/common.json' - next-translate Cannot find module './locales/en/common.json'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM