Unverified Commit 5a8ed815 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Define `typeof window` for application code only (#8355)

parent 7c09f713
......@@ -54,7 +54,9 @@
"examples/with-mobx/**",
"test/integration/client-navigation/pages/throw-undefined.js"
],
"globals": [ "performance" ]
"globals": [
"performance"
]
},
"devDependencies": {
"@babel/plugin-proposal-object-rest-spread": "7.4.4",
......
......@@ -562,17 +562,12 @@ export default async function getBaseWebpackConfig(
config.experimental.granularChunks && !selectivePageBuilding && !dev,
...(isServer
? {
// Allow browser-only code to be eliminated
'typeof window': JSON.stringify('undefined'),
// Fix bad-actors in the npm ecosystem (e.g. `node-formidable`)
// This is typically found in unmaintained modules from the
// pre-webpack era (common in server-side code)
'global.GENTLY': JSON.stringify(false),
}
: {
// Allow server-only code to be eliminated
'typeof window': JSON.stringify('object'),
}),
: undefined),
}),
!isServer &&
new ReactLoadablePlugin({
......
......@@ -116,12 +116,13 @@ module.exports = babelLoader.custom(babel => {
options.caller.isServer = isServer
options.plugins = options.plugins || []
if (!isServer && isPageFile) {
const pageConfigPlugin = babel.createConfigItem(
[require('../../babel/plugins/next-page-config')],
{ type: 'plugin' }
)
options.plugins = options.plugins || []
options.plugins.push(pageConfigPlugin)
}
......@@ -133,7 +134,6 @@ module.exports = babelLoader.custom(babel => {
],
{ type: 'plugin' }
)
options.plugins = options.plugins || []
options.plugins.push(nextDataPlugin)
}
......@@ -159,10 +159,14 @@ module.exports = babelLoader.custom(babel => {
// If the file has `module.exports` we have to transpile commonjs because Babel adds `import` statements
// That break webpack, since webpack doesn't support combining commonjs and esmodules
if (!hasModern && source.indexOf('module.exports') !== -1) {
options.plugins = options.plugins || []
options.plugins.push(applyCommonJs)
}
options.plugins.push([
'transform-define',
{ 'typeof window': isServer ? 'undefined' : 'object' }
])
// As next-server/lib has stateful modules we have to transpile commonjs
options.overrides = [
...(options.overrides || []),
......
......@@ -73,6 +73,7 @@
"babel-core": "7.0.0-bridge.0",
"babel-loader": "8.0.6",
"babel-plugin-react-require": "3.0.0",
"babel-plugin-transform-define": "1.3.1",
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
"chalk": "2.4.2",
"find-up": "4.0.0",
......
......@@ -3214,6 +3214,14 @@ babel-plugin-syntax-jsx@6.18.0:
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
integrity sha1-CvMqmm4Tyno/1QaeYtew9Y0NiUY=
babel-plugin-transform-define@1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-define/-/babel-plugin-transform-define-1.3.1.tgz#b21b7bad3b84cf8e3f07cdc8c660b99cbbc01213"
integrity sha512-JXZ1xE9jIbKCGYZ4wbSMPSI5mdS4DRLi5+SkTHgZqWn5YIf/EucykkzUsPmzJlpkX8fsMVdLnA5vt/LvT97Zbg==
dependencies:
lodash "^4.17.11"
traverse "0.6.6"
babel-plugin-transform-react-remove-prop-types@0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-remove-prop-types/-/babel-plugin-transform-react-remove-prop-types-0.4.24.tgz#f2edaf9b4c6a5fbe5c1d678bfb531078c1555f3a"
......@@ -13481,6 +13489,11 @@ tr46@^1.0.1:
dependencies:
punycode "^2.1.0"
traverse@0.6.6:
version "0.6.6"
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"
integrity sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc=
tree-kill@1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.1.tgz#5398f374e2f292b9dcc7b2e71e30a5c3bb6c743a"
......
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