Unverified Commit c219c1d9 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add polyfills for node_modules that are covered in webpack 4 to webpack 5 (#23316)

Brings back the remaining Node.js module polyfills to not break existing apps upgrading from webpack 4 to webpack 5.

Fixes #23169



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
parent 361b56b2
...@@ -393,11 +393,29 @@ export default async function getBaseWebpackConfig( ...@@ -393,11 +393,29 @@ export default async function getBaseWebpackConfig(
// Full list of old polyfills is accessible here: // Full list of old polyfills is accessible here:
// https://github.com/webpack/webpack/blob/2a0536cf510768111a3a6dceeb14cb79b9f59273/lib/ModuleNotFoundError.js#L13-L42 // https://github.com/webpack/webpack/blob/2a0536cf510768111a3a6dceeb14cb79b9f59273/lib/ModuleNotFoundError.js#L13-L42
fallback: { fallback: {
buffer: require.resolve('buffer'), assert: require.resolve('assert/'),
buffer: require.resolve('buffer/'),
constants: require.resolve('constants-browserify'),
crypto: require.resolve('crypto-browserify'), crypto: require.resolve('crypto-browserify'),
domain: require.resolve('domain-browser'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify/browser'),
path: require.resolve('path-browserify'), path: require.resolve('path-browserify'),
punycode: require.resolve('punycode'),
process: require.resolve('process/browser'),
// Handled in separate alias
querystring: require.resolve('querystring-es3'),
stream: require.resolve('stream-browserify'), stream: require.resolve('stream-browserify'),
string_decoder: require.resolve('string_decoder'),
sys: require.resolve('util/'),
timers: require.resolve('timers-browserify'),
tty: require.resolve('tty-browserify'),
// Handled in separate alias
// url: require.resolve('url/'),
util: require.resolve('util/'),
vm: require.resolve('vm-browserify'), vm: require.resolve('vm-browserify'),
zlib: require.resolve('browserify-zlib'),
}, },
} }
: undefined), : undefined),
......
...@@ -67,17 +67,22 @@ ...@@ -67,17 +67,22 @@
"@next/react-dev-overlay": "10.0.10-canary.7", "@next/react-dev-overlay": "10.0.10-canary.7",
"@next/react-refresh-utils": "10.0.10-canary.7", "@next/react-refresh-utils": "10.0.10-canary.7",
"@opentelemetry/api": "0.14.0", "@opentelemetry/api": "0.14.0",
"assert": "2.0.0",
"ast-types": "0.13.2", "ast-types": "0.13.2",
"browserify-zlib": "0.2.0",
"browserslist": "4.16.1", "browserslist": "4.16.1",
"buffer": "5.6.0", "buffer": "5.6.0",
"caniuse-lite": "^1.0.30001179", "caniuse-lite": "^1.0.30001179",
"chalk": "2.4.2", "chalk": "2.4.2",
"chokidar": "3.5.1", "chokidar": "3.5.1",
"constants-browserify": "1.0.0",
"crypto-browserify": "3.12.0", "crypto-browserify": "3.12.0",
"cssnano-simple": "1.2.2", "cssnano-simple": "1.2.2",
"domain-browser": "4.19.0",
"etag": "1.8.1", "etag": "1.8.1",
"find-cache-dir": "3.3.1", "find-cache-dir": "3.3.1",
"get-orientation": "1.1.2", "get-orientation": "1.1.2",
"https-browserify": "1.0.0",
"jest-worker": "27.0.0-next.5", "jest-worker": "27.0.0-next.5",
"native-url": "0.3.4", "native-url": "0.3.4",
"node-fetch": "2.6.1", "node-fetch": "2.6.1",
...@@ -89,12 +94,18 @@ ...@@ -89,12 +94,18 @@
"postcss": "8.1.7", "postcss": "8.1.7",
"process": "0.11.10", "process": "0.11.10",
"prop-types": "15.7.2", "prop-types": "15.7.2",
"querystring-es3": "0.2.1",
"raw-body": "2.4.1", "raw-body": "2.4.1",
"react-is": "16.13.1", "react-is": "16.13.1",
"react-refresh": "0.8.3", "react-refresh": "0.8.3",
"stream-browserify": "3.0.0", "stream-browserify": "3.0.0",
"stream-http": "3.1.1",
"string_decoder": "1.3.0",
"styled-jsx": "3.3.2", "styled-jsx": "3.3.2",
"timers-browserify": "2.0.12",
"tty-browserify": "0.0.1",
"use-subscription": "1.5.1", "use-subscription": "1.5.1",
"util": "0.12.3",
"vm-browserify": "1.1.2", "vm-browserify": "1.1.2",
"watchpack": "2.1.1" "watchpack": "2.1.1"
}, },
......
...@@ -3,7 +3,22 @@ import path from 'path' ...@@ -3,7 +3,22 @@ import path from 'path'
import crypto from 'crypto' import crypto from 'crypto'
import { Buffer } from 'buffer' import { Buffer } from 'buffer'
import vm from 'vm' import vm from 'vm'
import assert from 'assert'
import constants from 'constants'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import domain from 'domain'
import http from 'http'
import https from 'https'
import os from 'os'
import punycode from 'punycode'
import process from 'process'
import querystring from 'querystring'
import stringDecoder from 'string_decoder'
import sys from 'sys'
import timers from 'timers'
import tty from 'tty'
import util from 'util'
import zlib from 'zlib'
export default function NodeBrowserPolyfillPage() { export default function NodeBrowserPolyfillPage() {
const [state, setState] = useState({}) const [state, setState] = useState({})
...@@ -22,12 +37,39 @@ export default function NodeBrowserPolyfillPage() { ...@@ -22,12 +37,39 @@ export default function NodeBrowserPolyfillPage() {
writable.end() writable.end()
assert.ok(true)
assert.ok(!!domain)
assert.ok(!!http)
assert.ok(!!https)
assert.ok(!!punycode)
assert.ok(!!stringDecoder)
assert.ok(!!sys.debuglog)
assert.ok(!!timers.setInterval)
assert.ok(!!tty.ReadStream)
assert.ok(!!util.inspect)
assert.ok(!!zlib.Gzip)
setState({ setState({
path: path.join('/hello/world', 'test.txt'), assert: true,
hash: crypto.createHash('sha256').update('hello world').digest('hex'),
buffer: Buffer.from('hello world').toString('utf8'), buffer: Buffer.from('hello world').toString('utf8'),
vm: vm.runInNewContext('a + 5', { a: 100 }), constants: constants.E2BIG,
hash: crypto.createHash('sha256').update('hello world').digest('hex'),
domain: true,
os: os.EOL,
path: path.join('/hello/world', 'test.txt'),
process: process.title,
querystring: querystring.stringify({ a: 'b' }),
stream: closedStream, stream: closedStream,
stringDecoder: true,
sys: true,
timers: true,
tty: true,
util: true,
http: true,
https: true,
vm: vm.runInNewContext('a + 5', { a: 100 }),
zlib: true,
}) })
}, []) }, [])
......
...@@ -47,9 +47,20 @@ describe('Basic Features', () => { ...@@ -47,9 +47,20 @@ describe('Basic Features', () => {
expect(parsedData.hash).toBe( expect(parsedData.hash).toBe(
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
) )
expect(parsedData.path).toBe('/hello/world/test.txt')
expect(parsedData.buffer).toBe('hello world') expect(parsedData.buffer).toBe('hello world')
expect(parsedData.stream).toBe(true) expect(parsedData.stream).toBe(true)
expect(parsedData.assert).toBe(true)
expect(parsedData.constants).toBe(7)
expect(parsedData.domain).toBe(true)
expect(parsedData.http).toBe(true)
expect(parsedData.https).toBe(true)
expect(parsedData.os).toBe('\n')
expect(parsedData.path).toBe('/hello/world/test.txt')
expect(parsedData.process).toBe('browser')
expect(parsedData.querystring).toBe('a=b')
expect(parsedData.stringDecoder).toBe(true)
expect(parsedData.sys).toBe(true)
expect(parsedData.timers).toBe(true)
}) })
dynamic(context, (p, q) => renderViaHTTP(context.appPort, p, q)) dynamic(context, (p, q) => renderViaHTTP(context.appPort, p, q))
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment