Parcel: "http2" module

Created on 13 Apr 2019  ยท  13Comments  ยท  Source: parcel-bundler/parcel

Hi, developers! Thank you for your very convenient project.

โ” Question

Could you tell me Parcel supports "http2" module?

๐Ÿ”ฆ Context

const http2 = require("http2"); causes an error "Cannot resolve dependency 'http2'".
require("http") worked well.

๐Ÿ’ป Code Sample

Here is my index.js

// index.js
const http2 = require("http2");

http2.createServer((req, res)=>{
  res.end("hello, world\n");
}).listen(3000, ()=>{
  console.log("Listening...");
});

Here is how to build.

./node_modules/.bin/parcel build index.js --target=node --bundle-node-modules --no-cache

Here is the complete code: https://github.com/nwtgck/public-code/tree/master/parcel-http2

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.12.3|
| Node | v10.15.0 |
| npm/Yarn | npm 6.8.0 |
| Operating System | macOS 10.12.6 |

Bug Node Bundling โœจ Parcel 2

Most helpful comment

Any chances this fix makes it into parcel 1.X ?

All 13 comments

Parcel uses this list of node builtin modules: https://github.com/webpack/node-libs-browser/blob/master/index.js

EDIT: http2 and async_hooks are missing
It looks like we'll have to create our own version of that package because was actually deprecated a few days ago.

Unfortunately that list is missing a lot more than just http2

A package like that (a list of strings) isn't enough for our usecase, because some of these modules are actually polyfilled when bundling for the browser (e.g. buffer or path)

Ah I see. Not possible to use a separate package for polyfills and determining builtins?

Yes, I guess we could use some existing (maintained) package to make sure the builtin list is correct and use our own polyfill list

We can use the list that is exported from node itself:

import {builtinModules} from 'module';

Hey @devongovett, do you mean to use this package builtin-modules instead of node-libs-browser?

Webpack 5 might remove automatic Node polyfills (https://github.com/webpack/changelog-v5#automatic-nodejs-polyfills-removed)

Instead, they should be explicitly aliased (and the version can be specified, outdated polyfills were a problem in the past):

{
    "dependencies": {
        "path-browserify": "1.0.0"
    },
    "alias": {
        "path": "path-browserify"
    }
}

Should we do the same for Parcel 2?

Looks like this is fixed in #3620.

Any chances this fix makes it into parcel 1.X ?

I used this temporary solution.

Open node_modules/node-libs-browser/index.js and this line at the bottom:
image

I think that there are quite a lot of Parcel 1.X users out there who would like to use new NodeJS builtin modules. Is that possible to release a fix to the 1.X version?

2.x isn't even released, nor does it seem to be usable in its current state. Not sure why a fix for this isn't being pushed to 1.x... what the hell happened to this project?

Was this page helpful?
0 / 5 - 0 ratings