Unverified Commit d40d7d65 authored by Kristoffer K's avatar Kristoffer K Committed by GitHub

fix(next): resolve absolute path to @babel/runtime (#18921)

**What's the problem this PR addresses?**

https://github.com/vercel/next.js/pull/18768 started to ncc `@babel/plugin-transform-runtime` which broke its Yarn PnP support since the version of `resolve` it uses can't be patched by Yarn.

Fixes https://github.com/yarnpkg/berry/runs/1359235077?check_suite_focus=true#step:5:79

cc @guybedford

**How did you fix it?**

Resolve the absolute path to `@babel/runtime` so it doesn't have to go through `resolve`

---

Fixes https://github.com/vercel/next.js/issues/19026
parent a03fcbf7
import { PluginItem } from 'next/dist/compiled/babel/core' import { PluginItem } from 'next/dist/compiled/babel/core'
import { dirname } from 'path'
const env = process.env.NODE_ENV const env = process.env.NODE_ENV
const isProduction = env === 'production' const isProduction = env === 'production'
const isDevelopment = env === 'development' const isDevelopment = env === 'development'
...@@ -168,7 +170,9 @@ module.exports = ( ...@@ -168,7 +170,9 @@ module.exports = (
helpers: true, helpers: true,
regenerator: true, regenerator: true,
useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs', useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs',
absoluteRuntime: process.versions.pnp ? __dirname : undefined, absoluteRuntime: dirname(
require.resolve('@babel/runtime/package.json')
),
...options['transform-runtime'], ...options['transform-runtime'],
}, },
], ],
......
...@@ -64,8 +64,8 @@ describe('next/babel', () => { ...@@ -64,8 +64,8 @@ describe('next/babel', () => {
expect(output).toMatch(`__jsx(${react}.Fragment`) expect(output).toMatch(`__jsx(${react}.Fragment`)
expect(output).toMatch(`__jsx("a",{href:"/"`) expect(output).toMatch(`__jsx("a",{href:"/"`)
expect(babel(`const a = ()=><a href="/">home</a>`)).toMatchInlineSnapshot( expect(babel(`const a = ()=><a href="/">home</a>`)).toMatch(
`"\\"use strict\\";var _interopRequireDefault=require(\\"@babel/runtime/helpers/interopRequireDefault\\");var _react=_interopRequireDefault(require(\\"react\\"));var __jsx=_react[\\"default\\"].createElement;var a=function a(){return __jsx(\\"a\\",{href:\\"/\\"},\\"home\\");};"` `var _react=_interopRequireDefault(require("react"));var __jsx=_react["default"].createElement;var a=function a(){return __jsx("a",{href:"/"},"home");};`
) )
}) })
......
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