question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next.js cannot run in Yarn v2 PnP mode with "enableGlobalCache" enabled

See original GitHub issue

Bug report

Describe the bug

Next.js cannot run in Yarn v2 PnP mode with “enableGlobalCache” enabled.

To Reproduce

Execute following shell script.

mkdir pages
cat <<'EOF' > pages/index.js
export default function Index() {
  return <h1>Hi</h1>
}
EOF

cat <<'EOF' > package.json
{
  "dependencies": {
    "next": "9.5.1",
    "react": "16.13.1",
    "react-dom": "16.13.1"
  }
}
EOF

yarn set version berry
yarn config set enableGlobalCache true
yarn install
yarn next dev

Expected behavior

Next.js server should be started.

Screenshots

image

error - ./.yarn/$$virtual/next-virtual-061300f485/3/.yarn/berry/cache/next-npm-9.4.5-canary.39-f06383efbf-5.zip/node_modules/next/dist/client/dev/amp-dev.js
Error: [BABEL] /home/simnalamburt/workspace/a/.yarn/$$virtual/next-virtual-061300f485/3/.yarn/berry/cache/next-npm-9.4.5-canary.39-f06383efbf-5.zip/node_modules/next/dist/client/dev/amp-dev.js: Failed to resolve "@babel/runtime" relative to "/home/simnalamburt/workspace/a/.yarn/$$virtual/next-virtual-061300f485/3/.yarn/berry/cache/next-npm-9.4.5-canary.39-f06383efbf-5.zip/node_modules/next/dist/build/babel" (While processing: "programmatic item$6")
    at Array.reduce (<anonymous>)

System information

  • OS: Debian GNU/Linux 10
  • Version of Next.js: Reproducible in 9.4.4, 9.4.5-canary.31, 9.4.5-canary.39, 9.5.1
  • Version of Node.js: v14.5.0

Additional context

It seems to be a problem with some of the dependencies used by Next.js. I want to know which dependencies cause problems.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jdmotacommented, Aug 2, 2020

@simnalamburt No problem! But I think this is more related to the resolve package. For some reason, the PnP Api is not getting injected…

@arcanis, do you know what the issue is? Thanks!

1reaction
jdmotacommented, Aug 1, 2020

I also encountered the same issue in version 9.5.1. Managed to workaround it by applying the following patch to @babel/plugin-transform-runtime.

diff --git a/lib/get-runtime-path/index.js b/lib/get-runtime-path/index.js
index 354208c9eaaec10e5067156c004ff7a32fcfa921..483a5bd2b5ee17b65719c7fa3934e1c694d22e8b 100644
--- a/lib/get-runtime-path/index.js
+++ b/lib/get-runtime-path/index.js
@@ -18,9 +18,17 @@ function _default(moduleName, dirname, absoluteRuntime) {
 
 function resolveAbsoluteRuntime(moduleName, dirname) {
   try {
-    return _path.default.dirname(_resolve.default.sync(`${moduleName}/package.json`, {
-      basedir: dirname
-    })).replace(/\\/g, "/");
+    var pkg;
+    if (process.versions.pnp) {
+      pkg = require("pnpapi").resolveRequest(`${moduleName}/package.json`, dirname, {
+        considerBuiltins: false
+      });
+    } else {
+      pkg = _resolve.default.sync(`${moduleName}/package.json`, {
+        basedir: dirname
+      });
+    }
+    return _path.default.dirname(pkg).replace(/\\/g, "/");
   } catch (err) {
     if (err.code !== "MODULE_NOT_FOUND") throw err;
     throw Object.assign(new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`), {

And adding this to package.json:

"resolutions": {
  "next/@babel/plugin-transform-runtime": "patch:@babel/plugin-transform-runtime@7.9.6#./transform-runtime.patch"
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js 13: Build failure when enabling appDir and using Yarn ...
When using Yarn PnP to manage packages, running next bulid with appDir enabled will fail to build. The build log is:.
Read more >
Next.js with Yarn pnp in a mono repo keep failing when trying ...
It seems like the main problem here is the build tool, because when I run the Next.js server itself ( yarn dev )...
Read more >
Advanced package manager features for npm, Yarn, and pnpm
PnP is the default mode of Yarn Berry, but you can also explicitly enable it within .yarnrc.yml . # .yarnrc.yml # alternatively, remove...
Read more >
Yarn Zero-Installs & Plug'n'Play – PAKDB - Jesidea
In this install mode (the default starting from Yarn 2.0), Yarn generates a single .pnp.cjs file instead of the usual node_modules folder containing...
Read more >
esbuild-linux-s390x - NPM Package Versions - Socket.dev
The Linux IBM Z 64-bit Big Endian binary for esbuild, a JavaScript bundler. Version: 0.15.10 was published by evanw.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found