vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.93k stars 26.87k forks source link

Nodemon loop on npm run dev #6343

Closed sstrubberg closed 5 years ago

sstrubberg commented 5 years ago

Bug report

Nodemon is in a permanent loop after adding distDir to next.config.js.

feb-18-2019 14-54-51

next.config.js

const withCSS = require("@zeit/next-css");
const withSass = require("@zeit/next-sass");

module.exports = withCSS(
  withSass({
    distDir: "design/career",
    sassLoaderOptions: {
      includePaths: ["node_modules"]
    },

    webpack(config, options) {
      config.module.rules.push({
        test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
        use: {
          loader: "url-loader",
          options: {
            limit: 100000
          }
        }
      });
      return config;
    }
  })
);

server.js

// This file doesn't go through babel or webpack transformation.
// Make sure the syntax and sources this file requires are compatible with the current node version you are running
// See https://github.com/zeit/next.js/issues/1245 for discussions on Universal Webpack or universal Babel
const { createServer } = require("http");
const { parse } = require("url");
const next = require("next");

const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
const port = process.env.PORT || 3000;

app.prepare().then(() => {
  createServer((req, res) => {
    // Be sure to pass `true` as the second argument to `url.parse`.
    // This tells it to parse the query portion of the URL.
    const parsedUrl = parse(req.url, true);
    const { pathname, query } = parsedUrl;

    if (pathname === "/a") {
      app.render(req, res, "/b", query);
    } else if (pathname === "/b") {
      app.render(req, res, "/a", query);
    } else {
      handle(req, res, parsedUrl);
    }
  }).listen(port, err => {
    if (err) throw err;
    console.log("> Ready on http://localhost:3000");
  });
});

package.json

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon -w server/**/* server.js",
    "build": "next build",
    "start": "npm run dev",
  },
"dependencies": {
    "@carbon/colors": "0.0.1-alpha.31",
    "@carbon/icons-react": "0.0.1-alpha.31",
    "@carbon/layout": "0.0.1-alpha.31",
    "@carbon/type": "0.0.1-alpha.31",
    "@zeit/next-css": "^1.0.1",
    "@zeit/next-sass": "^1.0.1",
    "carbon-components": "^9.69.1",
    "carbon-components-react": "^6.85.0",
    "carbon-icons": "^7.0.7",
    "grid-wiz": "^1.0.0",
    "next": "^7.0.3",
    "next-ga": "^2.3.4",
    "node-sass": "^4.10.0",
    "prop-types": "^15.7.1",
    "react": "^16.5.2",
    "react-accessible-accordion": "^2.4.5",
    "react-dom": "^16.5.2",
    "react-light-accordion": "^0.1.4",
    "react-sticky": "^6.0.3",
    "react-tabs": "^2.3.0",
    "styled-components": "^4.0.2",
    "url-loader": "^1.1.2"
  },
  "devDependencies": {
    "nodemon": "^1.18.6"
  }

Expected behavior

It loads fine when I remove the distDir line. Makes me wonder I'm putting it in the wrong spot, but my face hurts from hitting it against the wall :)

timneutkens commented 5 years ago

This doesn't sound related to Next.js, at least it's not a bug.

It sounds like the nodemon watcher is picking up file changes, maybe the distDir is being written into the server dir 🤔

sstrubberg commented 5 years ago

Hey @timneutkens. Thanks for checking in regarding the issue.

Turns out I was able to fix the endless loop by fixing the distDir line in my next.config.j file.

I replaced distDir: "design/career", with distDir: ".design/career",. No more loops!

colin-byrne-1 commented 5 years ago

^ same as above. I had this error and my dist directory was nested improperly.

macorifice commented 4 years ago

add this follow lines in nodemon.json: { "verbose": true, "ignore": ["node_modules", ".next"], "watch": ["server/*/", "server.js"], "ext": "js json" }

balazsorban44 commented 2 years ago

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.