Issue 1:
I am trying to build a zip file only containing the code I need for production deployment. Smaller builds benefit nearly all production users: cheaper to store indefinitely, quicker to roll out after build finish, faster to load cold start in serverless, and for large projects it is easy to go over serverless dist limits without optimized distribution. I believe rollout is the best option for getting an optimized build.

The good news, running rollup turns my 60m dist file into 6m. I believe this concept will be a huge win for people who want their next.js app to start as quick as possible.

Bad news: When I try to run rollup on my next.js build, I get a circular dependency issue that I believe stops the result from running:

(!) Circular dependency: node_modules\next\dist\lib\router\index.js -> node_modules\next\dist\lib\router\router.js -> node_modules\next\dist\lib\router\index.js
(!) Circular dependency: node_modules\next\dist\lib\router\index.js -> node_modules\next\dist\lib\router\router.js -> commonjs-proxy:<FULL_PATH_TO_HERE>\node_modules\next\dist\lib\router\index.js -> node_modules\next\dist\lib\router\index.js

Would it be possible to not have a circular dependency between index.js and routes.js?

Here are the files I am using for testing this, hopefully this might help someone more experienced carry on from where I am stuck:

rollup.config.js

import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import resolve from "rollup-plugin-node-resolve";
import replace from "rollup-plugin-replace";
import json from 'rollup-plugin-json';

const NODE_ENV = process.env.NODE_ENV || "development";
const outputFile = NODE_ENV === "production" ? "./lib/prod.js" : "./lib/dev.js";

export default {
input: "./server.js",
output: {
file: outputFile,
format: "cjs"
},
plugins: [
replace({
"process.env.NODE_ENV": JSON.stringify(NODE_ENV)
}),
json(),
babel({
exclude: ["node_modules/**"]
}),
resolve({
preferBuiltins: true
}),
commonjs()
],
external: ["webpack", "readable-stream", "glob", "source-list-map", "through2" ]
};

(external has a few exclusions due to circular dependencies that need to be taken up with those package owners.)

"devDependencies": {
...
"rollup": "^0.66.4",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-replace": "^2.1.0"
}

create rollup (note circular dependency issue)

NODE_ENV=production rollup -c

to run

node lib/prod.js

error I get but I suspect it is because of circular dependency

C:\Users\Adam\code\gell\gell-client-west\lib\prod.js:135129
const childModule = commonjsRequire.resolve('./child/index');
^

TypeError: commonjsRequire.resolve is not a function
at Object.<anonymous> (lib\prod.js:135129:38)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:279:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)

Can anyone weigh in on:

how hard it would be to rewrite next\dist\lib\router\index.js -> next\dist\lib\router\router.js without circular dependency? Could the router.js code just be included directly into index.js?

Is "commonjsRequire.resolve is not a function" error due to the circular dependency or something else?

Issue 2:
I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

When I was reading source codes of next.js, I found an interesting place, https://github.com/zeit/next.js/blob/canary/lib/router/router.js#L138.

We'd better to return true there? Those codes were introduced by #1250.

Current Behavior

Return without explicit boolean value.