Skip to content

Commit

Permalink
fix(next): always enable absoluteRuntime when running under webpack (#…
Browse files Browse the repository at this point in the history
…19538)

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

In #18921 I enabled `absoluteRuntime` for everyone (it was only enabled for PnP users) but didn't consider that people used the babel preset outside of the webpack build.

Fixes #19448 - ~~Since it doesn't contain a repro I can't be certain but based on feedback from @koshea in #18921 (comment) I'll assume @RossMcMillan92 is doing the same thing, because when next is building it doesn't leave absolute paths as external.~~
Confirmed in #18921 (comment)

**How did you fix it?**

Only enable `absoluteRuntime` when the preset is running under `babel-loader`
  • Loading branch information
merceyz committed Jan 11, 2021
1 parent b3a6313 commit 4e3eb73
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/next/build/babel/preset.ts
Expand Up @@ -77,6 +77,10 @@ module.exports = (
// Default to production mode if not `test` nor `development`:
const isProduction = !(isTest || isDevelopment)

const isBabelLoader = api.caller(
(caller: any) => !!caller && caller.name === 'babel-loader'
)

const useJsxRuntime =
options['preset-react']?.runtime === 'automatic' ||
(Boolean(api.caller((caller: any) => !!caller && caller.hasJsxRuntime)) &&
Expand Down Expand Up @@ -180,7 +184,7 @@ module.exports = (
helpers: true,
regenerator: true,
useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs',
absoluteRuntime: process.versions.pnp
absoluteRuntime: isBabelLoader
? dirname(require.resolve('@babel/runtime/package.json'))
: undefined,
...options['transform-runtime'],
Expand Down

0 comments on commit 4e3eb73

Please sign in to comment.