Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/next/build/babel/preset.ts
@@ -1,4 +1,6 @@
import { PluginItem } from 'next/dist/compiled/babel/core'
import { dirname } from 'path'

const env = process.env.NODE_ENV
const isProduction = env === 'production'
const isDevelopment = env === 'development'
Expand Down Expand Up @@ -168,7 +170,9 @@ module.exports = (
helpers: true,
regenerator: true,
useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs',
absoluteRuntime: process.versions.pnp ? __dirname : undefined,
absoluteRuntime: dirname(
require.resolve('@babel/runtime/package.json')
),
...options['transform-runtime'],
},
],
Expand Down
4 changes: 2 additions & 2 deletions test/unit/next-babel.unit.test.js
Expand Up @@ -64,8 +64,8 @@ describe('next/babel', () => {
expect(output).toMatch(`__jsx(${react}.Fragment`)
expect(output).toMatch(`__jsx("a",{href:"/"`)

expect(babel(`const a = ()=><a href="/">home</a>`)).toMatchInlineSnapshot(
`"\\"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\\");};"`
expect(babel(`const a = ()=><a href="/">home</a>`)).toMatch(
`var _react=_interopRequireDefault(require("react"));var __jsx=_react["default"].createElement;var a=function a(){return __jsx("a",{href:"/"},"home");};`
)
})

Expand Down