diff --git a/packages/next/build/babel/preset.ts b/packages/next/build/babel/preset.ts index 700ddb5260772..9a52dabb1fad2 100644 --- a/packages/next/build/babel/preset.ts +++ b/packages/next/build/babel/preset.ts @@ -77,6 +77,25 @@ module.exports = (api: any, options: NextBabelPresetOptions = {}): BabelPreset = // Transform dynamic import to require isTest && require('babel-plugin-dynamic-import-node'), require('./plugins/react-loadable-plugin'), + [ + require('@babel/plugin-transform-destructuring'), + { + useBuiltIns: true, + loose: false, + selectiveLoose: [ + 'useState', + 'useEffect', + 'useContext', + 'useReducer', + 'useCallback', + 'useMemo', + 'useRef', + 'useImperativeHandle', + 'useLayoutEffect', + 'useDebugValue', + ], + }, + ], [require('@babel/plugin-proposal-class-properties'), options['class-properties'] || {}], require('@babel/plugin-proposal-object-rest-spread'), [require('@babel/plugin-transform-runtime'), { diff --git a/packages/next/package.json b/packages/next/package.json index 0d7c1e39119bd..f6b87a617ea3a 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -43,6 +43,7 @@ "@babel/plugin-proposal-class-properties": "7.1.0", "@babel/plugin-proposal-object-rest-spread": "7.0.0", "@babel/plugin-syntax-dynamic-import": "7.0.0", + "@babel/plugin-transform-destructuring": "7.4.0", "@babel/plugin-transform-modules-commonjs": "7.1.0", "@babel/plugin-transform-runtime": "7.1.0", "@babel/preset-env": "7.1.0", diff --git a/yarn.lock b/yarn.lock index cb5e26482823a..b02ae73531fe2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -416,6 +416,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-transform-destructuring@7.4.0": + version "7.4.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.4.0.tgz#acbb9b2418d290107db333f4d6cd8aa6aea00343" + integrity sha512-HySkoatyYTY3ZwLI8GGvkRWCFrjAGXUHur5sMecmCIdIharnlcWWivOqDJI76vvmVZfzwb6G08NREsrY96RhGQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-destructuring@^7.0.0": version "7.3.2" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.3.2.tgz#f2f5520be055ba1c38c41c0e094d8a461dd78f2d"