airbnb / hypernova

A service for server-side rendering your JavaScript views
MIT License
5.82k stars 207 forks source link

TypeError: Promise.promisifyAll is not a function #134

Open juanca opened 6 years ago

juanca commented 6 years ago

Environment:

> node --version
v8.11.1

I'm starting to set up hypernova in a Rails + Webpack repository.

By importing the hypernova server module, it seems my globals are polluted.

The only difference in my script is the following line:

const hypernova = require('hypernova/server');

which produces the following error trace:

yarn run v1.6.0
$ node script/hypernova.js
/Users/juanca/workspace/project/node_modules/html-webpack-plugin/index.js:10
Promise.promisifyAll(fs);
        ^

TypeError: Promise.promisifyAll is not a function
    at Object.<anonymous> (/Users/juanca/workspace/project/node_modules/html-webpack-plugin/index.js:10:9)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/juanca/workspace/project/config/helpers/generate-error-pages.js:4:27)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

While the error is not in the hypernova source, it is being caused by a hypernova module -- since it works without processing the module.

I was wondering whether this is true, whether this is fixable, whether this is intended, etc. I would be happy to make a PR if it is an acceptable improvement: removing dependencies on the global Promise object.

ljharb commented 6 years ago

hypernova used bluebird, but doesn’t shim anything; promisifyAll is a bluebird method. Perhaps you have code that is relying on bluebird being the global Promise?

juanca commented 6 years ago

I looked into it a bit more.

I have been able to isolate the side effects with the following code:

var Promise = require('bluebird');
console.log(Promise.promisifyAll);

const hypernova = require('hypernova/server');
console.log(Promise.promisifyAll);

which outputs the following:

yarn run v1.6.0
$ node script/hypernova.js
[Function]
undefined

I'm going to dig into hypernova/server now -- though at a quick glance I can't seem to find any reference to bluebird.


For the sake of more information:

yarn why v1.6.0
[1/4] 🤔  Why do we have the module "bluebird"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "bluebird@3.5.1"
info Reasons this module exists
   - "karma" depends on it
   - Hoisted from "karma#bluebird"
   - Hoisted from "html-webpack-plugin#bluebird"
   - Hoisted from "svg-sprite-loader#bluebird"
   - Hoisted from "hypernova#bluebird"
   - Hoisted from "svg-sprite-loader#svg-baker#bluebird"
   - Hoisted from "webpack-bundle-analyzer#bfj-node4#bluebird"
   - Hoisted from "karma#log4js#amqplib#bluebird"
   - Hoisted from "react-styleguidist#copy-webpack-plugin#cacache#bluebird"
info Disk size without dependencies: "192MB"
info Disk size with unique dependencies: "192MB"
info Disk size with transitive dependencies: "192MB"
info Number of shared dependencies: 0
   Done in 1.28s.
juanca commented 6 years ago

It seems that node_modules/hypernova/lib/environment.js is modifying the exported module from bluebird.

What's the intention of that file?


I'll open a PR in case we want some changes.

ljharb commented 6 years ago

ah, it's to ensure that the global promise lacks Bluebird-specific methods.