I have a basic set up with a custom server going. This first time I've seen this error. I can't seem to figure this out.
Running NPMv5 and Nodev8.
// server.js
const express = require('express');
const next = require('next');
const bodyParser = require('body-parser');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
  const server = express();
  server.use(bodyParser.json());
  server.get('*', (req, res) => handle(req, res));
  server.listen(3000, err => {
    if (err) throw err;
    console.log('Next running on http://localhost:3000');
  });
});
// pages/index.js
import React from 'react';
export default function Hello() {
  return <h1>Hello</h1>;
}
my package.json
{
  "name": "rentpen",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.16.2",
    "body-parser": "^1.17.2",
    "express": "^4.15.3",
    "mongoose": "^4.10.6",
    "next": "^2.4.4",
    "next-redux-wrapper": "^1.1.2",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-redux": "^5.0.5",
    "redux": "^3.7.0",
    "redux-thunk": "^2.2.0"
  },
  "devDependencies": {
    "babel-eslint": "^7.2.3",
    "babel-preset-stage-0": "^6.24.1",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^15.0.1",
    "eslint-plugin-import": "^2.3.0",
    "eslint-plugin-jsx-a11y": "^5.0.3",
    "eslint-plugin-react": "^7.1.0"
  }
}
                        The following fixed my issue, but I've never had to install amdefine before. Is this new?
npm install -g amdefine
rm -rf node_modules
npm install
                    Doing a yarn why on the dependency shows it's a dependency of react-hot-loader. What version of npm are you on? npm --version. The latest version is 5.0.3. I just tried to reproduce but I couldn't so I'm going to close this.
➜  test2 yarn why amdefine
yarn why v0.24.5
[1/4] 🤔  Why do we have the module "amdefine"...?
[2/4] 🚚  Initialising dependency graph...
warning No license field
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
info This module exists because "next#react-hot-loader#source-map" depends on it.
                    I had to npm i amdefine to get this to work. I mean it's fine now. Just something I've never had to do before on my next projects, and I don't see it documented anywhere.
Node 8.1
NPM 5.0.3
It's not documented cause you shouldn't have to. It's a sub-sub dependency of Next.js. Maybe something went wrong with npm 🤔
Maybe. That's my point. I shouldn't have to install this manually.
I just faced this same issue. Looks like there is a critical new step for starting fresh when using npm 5. You also need to remove the package-lock.json file.
This worked for me:
rm -rf node_modules
rm -rf package-lock.json
npm install
                    Thank you @ftorre104 - that worked!
Had the same problem - thanks!
Most helpful comment
I just faced this same issue. Looks like there is a critical new step for starting fresh when using npm 5. You also need to remove the package-lock.json file.
This worked for me: