Ncc: Error: Cannot find module 'http' (browserify + uglify bug)

Created on 4 Mar 2019  路  7Comments  路  Source: vercel/ncc

Most helpful comment

@EnixCoda I am able to reproduce this bug.

  1. Clone this branch
  2. Change now.json env to the following:
  {
    "FIREBASE": "eyJoZWxsbyI6ICJ3b3JsZCJ9",
    "VERIFICATION_TOKEN": "token",
    "CLIENT_SECRET": "client",
    "CLIENT_ID": "id",
    "SIGNING_SECRET": "secret",
    "NODE_ENV": "production"
  },
  1. Run ncc build src/github.js
  2. Run node dist/index.js

Error: Cannot find module 'http'
    at s (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:262)
    at /Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:419
    at Object.1.http (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:601)
    at s (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:368)
    at /Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:419
    at Object.3../_read (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:4286)
    at s (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:368)
    at e (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:534)
    at /Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:554
    at module.exports.364 (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:61)

@guybedford Can you look into this bug?

All 7 comments

@styfle

@EnixCoda I actually can't see the logs because your deployment is set to private.

So I found your source code and deployed that branch myself and I got a different error.

Error: The lambda function size (5.31mb) exceeds the configured limit (5mb). You may increase this by supplying maxLambdaSize to the build config

It works fine after adding that config to now.json like so:

"builds": [
    { "src": "src/gateway.js", "use": "@now/node", "config": { "maxLambdaSize": "6mb" } },
    { "src": "src/routes/github.js", "use": "@now/node", "config": { "maxLambdaSize": "6mb" } },
    { "src": "src/routes/bot.js", "use": "@now/node", "config": { "maxLambdaSize": "6mb" } },
    { "src": "src/routes/interactive.js", "use": "@now/node", "config": { "maxLambdaSize": "6mb" } },
    { "src": "src/routes/oauth.js", "use": "@now/node", "config": { "maxLambdaSize": "6mb" } }
  ]

Although I do think gateway.js is strange 馃

@styfle Sorry I thought the logs were public.馃槄

For the gateway.js:
I got Cannot find module 'http' error when I was using @now/node. Then I found an issue says that dynamic require might fail in some cases. So I made the gateway.js to test if it was that caused the error.

Did you try paths other than /? I deployed again just now and other paths are still down :(

For example, /github throws 500:

Logs of that request

03/05 10:50 AM (7m)
(output/src/routes/github.js)
{ Error: Cannot find module 'http'
    at s (/var/task/user/src/routes/github.js:5283:262)
    at /var/task/user/src/routes/github.js:5283:419
    at Object.1.http (/var/task/user/src/routes/github.js:5283:601)
    at s (/var/task/user/src/routes/github.js:5283:368)
    at /var/task/user/src/routes/github.js:5283:419
    at Object.3../_read (/var/task/user/src/routes/github.js:5283:4286)
    at s (/var/task/user/src/routes/github.js:5283:368)
    at e (/var/task/user/src/routes/github.js:5283:534)
    at /var/task/user/src/routes/github.js:5283:554
    at module.exports.240.i (/var/task/user/src/routes/github.js:5283:61) code: 'MODULE_NOT_FOUND' }


BTW it does surprise me that you could find the source code repo and the right branch.馃ぃ

@EnixCoda I am able to reproduce this bug.

  1. Clone this branch
  2. Change now.json env to the following:
  {
    "FIREBASE": "eyJoZWxsbyI6ICJ3b3JsZCJ9",
    "VERIFICATION_TOKEN": "token",
    "CLIENT_SECRET": "client",
    "CLIENT_ID": "id",
    "SIGNING_SECRET": "secret",
    "NODE_ENV": "production"
  },
  1. Run ncc build src/github.js
  2. Run node dist/index.js

Error: Cannot find module 'http'
    at s (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:262)
    at /Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:419
    at Object.1.http (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:601)
    at s (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:368)
    at /Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:419
    at Object.3../_read (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:4286)
    at s (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:368)
    at e (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:534)
    at /Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:554
    at module.exports.364 (/Users/styfle/Desktop/github-code-review-notifier/dist/index.js:31777:61)

@guybedford Can you look into this bug?

@sokra the error here appears to be from bundling https://unpkg.com/[email protected]/bundle.js causing the require to not be referencing the __non_webpack_require__ of this webpack bundle itself.

If I try running webpack directly on this file as well it doesn't seem to work.

Is this a Webpack bug in not supporting bundling a webpack bundle? Or should we add custom support for this specific wrapper in ncc? Would value your thoughts.

@guybedford The source code of tiny-json-http was not run through webpack.

It was run through browserify and then uglifyjs as seen in the package.json script.

So it seems like this is a bug in ncc so let's fix it 馃憤

If I try running webpack directly on this file as well it doesn't seem to work.

Maybe we could get more information about "doesn't seem to work" 馃

Perfect, thanks for the clarification here @styfle. In that case this is a simple modification of our browserify wrapper I will look into.

Was this page helpful?
0 / 5 - 0 ratings