Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module http #273

Closed
tunnckoCore opened this issue Feb 7, 2019 · 16 comments
Closed

Cannot find module http #273

tunnckoCore opened this issue Feb 7, 2019 · 16 comments

Comments

@tunnckoCore
Copy link

tunnckoCore commented Feb 7, 2019

Pretty strange.

2019-02-07T20:11:44.377Z  success Already up-to-date.
2019-02-07T20:11:44.380Z  Done in 0.10s.
2019-02-07T20:11:44.868Z  yarn cache v1.12.3
2019-02-07T20:11:44.905Z  warning package.json: No license field
2019-02-07T20:11:44.923Z  success Cleared cache.
2019-02-07T20:11:44.924Z  Done in 0.06s.
2019-02-07T20:11:56.464Z  { Error: Cannot find module 'http'
                              at s (/var/task/user/index.js:20677:262)
                              at /var/task/user/index.js:20677:419
                              at Object.1.http (/var/task/user/index.js:20677:601)
                              at s (/var/task/user/index.js:20677:368)
                              at /var/task/user/index.js:20677:419
                              at Object.3../_read (/var/task/user/index.js:20677:4298)
                              at s (/var/task/user/index.js:20677:368)
                              at e (/var/task/user/index.js:20677:534)
                              at /var/task/user/index.js:20677:554
                              at module.exports.i (/var/task/user/index.js:20677:61) code: 'MODULE_NOT_FOUND' }
2019-02-07T20:11:56.475Z  Error while initializing entrypoint: { Error: Cannot find module 'http'
                              at s (/var/task/user/index.js:20677:262)
                              at /var/task/user/index.js:20677:419
                              at Object.1.http (/var/task/user/index.js:20677:601)
                              at s (/var/task/user/index.js:20677:368)
                              at /var/task/user/index.js:20677:419
                              at Object.3../_read (/var/task/user/index.js:20677:4298)
                              at s (/var/task/user/index.js:20677:368)
                              at e (/var/task/user/index.js:20677:534)
                              at /var/task/user/index.js:20677:554
                              at module.exports.i (/var/task/user/index.js:20677:61) code: 'MODULE_NOT_FOUND' }
2019-02-07T20:11:56.476Z  REPORT RequestId: 5af847b9-7f68-4260-9279-843409332d98	Duration: 4.25 ms	Billed Duration: 100 ms 	Memory Size: 3008 MB	Max Memory Used: 67 MB	

With now.json

{
  "name": "slack-nda",
  "alias": "slack-nda.now.sh",
  "version": 2,
  "builds": [
    {
      "src": "*.js",
      "use": "@now/node"
    }
  ],
  "env": {
    "SLACK_ACCESS_TOKEN": "@tunnckocorehq-slack-nda-token",
    "SLACK_CLIENT_ID": "@tunnckocorehq-slack-nda-client-id",
    "SLACK_CLIENT_SECRET": "@tunnckocorehq-slack-nda-client-secret"
  }
}

I was using node-fetch, then switched to axios and still fails. Which make sense, since it's built-in module :D But.. I can't understand where this error can come from. Stack traces doesn't help too?

@rauchg
Copy link
Member

rauchg commented Feb 7, 2019

Could you please provide some more repro instructions? (gave you some pointers on this on Slack)

@tunnckoCore
Copy link
Author

tunnckoCore commented Feb 7, 2019

Yup. I'll create repo soon.

{
  "private": true,
  "name": "slack-nda",
  "version": "0.1.0",
  "main": "index.js",
  "license": "Apache-2.0",
  "devDependencies": {
    "eslint": "^5.13.0",
    "eslint-config-tunnckocore": "^3.0.0",
    "prettier": "^1.16.4"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "dateformat": "^3.0.3",
    "docx-templates": "^2.9.1",
    "fs-extra": "^7.0.1",
    "micro": "^9.3.3",
    "slack": "^11.0.1"
  }
}

@tunnckoCore
Copy link
Author

Repo for reproduce: https://github.com/tunnckoCore/slack-nda

Latest deployment: https://slack-zeit-nda-4dcvv9nkp.now.sh/

Once we hit it, it gives us that error.

@porsager
Copy link

porsager commented Feb 7, 2019

I'm seeing the same thing with 0.14.0 and https

@porsager
Copy link

porsager commented Feb 7, 2019

Ok, I did a bit more digging, and in my case it was due to a module generating the require string dynamically like require(url.protocol.slice(0, -1)). It worked fine after changing it to this:

url.protocol === 'https:' ? require('https') : require('http')

I don't know if this is something ncc is able to handle?

@tunnckoCore
Copy link
Author

Whatever it is, it does not make sense to error, since both modules exist in nodejs :D Pretty strange error. Debugging isn't quite easy because everything is bundled and not in your machine so you can't follow the stacktrace.

But anyway, I couldn't find what was wrong, but continued with refactoring and it disappeared.

@rauchg
Copy link
Member

rauchg commented Feb 12, 2019

@porsager would you mind submitting a PR with that minimal test case?

@guybedford
Copy link
Contributor

I've added a fix here in vercel/webpack-asset-relocator-loader@590d2ab. Will post the update PR shortly.

@porsager
Copy link

@rauchg sorry, seems @guybedford beat me to it :) Nice job!

And thank you for an awesome tool. This really cleans up our distributed apps!

@styfle
Copy link
Member

styfle commented Feb 15, 2019

Fixed in ncc@0.15.1

@styfle styfle closed this as completed Feb 15, 2019
@EnixCoda
Copy link

EnixCoda commented Mar 1, 2019

Is the fix released? I'm still getting this error.

@styfle
Copy link
Member

styfle commented Mar 1, 2019

@EnixCoda It was released in @now/node@canary but not the stable @now/node yet.

@EnixCoda
Copy link

EnixCoda commented Mar 1, 2019

@styfle Thanks for replying!
I tried @now/node@canary and got another error: Unable to import module 'launcher'.
Maybe I'd better wait for next stable release...

BTW, how can I subscribe to release updates?

@tunnckoCore
Copy link
Author

@EnixCoda, github recently added such feature, click the watch button and then "releases only".

@EnixCoda
Copy link

EnixCoda commented Mar 1, 2019

@tunnckoCore I see, thank you!

@styfle
Copy link
Member

styfle commented Mar 1, 2019

@EnixCoda Can you create a new issue and provide the source code to reproduce this bug? Thanks!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants