vercel / turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
https://turbo.build/repo/docs
MIT License
26.05k stars 1.79k forks source link

[turbopack] NextJS monorepo issue with pnpm workspace #2783

Closed Alexandredc closed 1 year ago

Alexandredc commented 1 year ago

What version of Turbopack are you using?

next@13.0.4

What package manager are you using / does the bug impact?

pnpm

What operating system are you using?

Mac

Describe the Bug

Hello,

I have tried to test turbopack with monorepo structure with PNPM workspace but I encounter this issue : Error: Cannot find module 'next/dist/server/node-polyfill-fetch'

Without workspace, the project is bundled correctly.

I already try lot of things like : pnpm install --shamefully-hoist node-linker:hoisted

But nothing work correctly.

I noticed that the same problem exist with yarn workspace.

Expected Behavior

NextJs app should be bundled correctly with turbopack.

To Reproduce

I made a example in Github repo : https://github.com/Alexandredc/next-turbopack-monorepo-issue

pnpm install
cd apps/app
pnpm dev

Reproduction Repo

https://github.com/Alexandredc/next-turbopack-monorepo-issue

WEB-1044

unitof commented 1 year ago

Odd, --turbo dev worked for me in a next@13.3 project within a monorepo, but no broke after upgrade to 13.4, with this same error within a 500 page: Error: Cannot find module 'next/dist/server/node-polyfill-fetch'

image

npx next dev from the same directory builds and runs fine.

padmaia commented 1 year ago

This looks resolved with Next.js 13.4

unitof commented 1 year ago

It’s actually upgrading to 13.4 which made it start for me.

Tried clearing all .cache files and doing a npm reinstall.

But agree maybe I’m facing a separate issue.

Comma, Jacob Ford Designer http://jacobford.comAbout http://nocomment.llcTown

Sent from my Underwood Portable 4-Bank

On May 10, 2023 at 5:40:53 PM, Maia Teegarden @.***> wrote:

This looks resolved with Next.js 13.4

— Reply to this email directly, view it on GitHub https://github.com/vercel/turbo/issues/2783#issuecomment-1542843151, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASV3DRKSM4TBDK3MF5SIHDXFQDOLANCNFSM6AAAAAASGYVRCU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

maltesa commented 1 year ago

This looks resolved with Next.js 13.4

Still facing the issue with 13.4. Cleared all caches and reinstalled all packages:

Error: Cannot find module 'next/dist/server/node-polyfill-fetch'

Debug info:
- Error: Cannot find module 'next/dist/server/node-polyfill-fetch'
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_polyfill_app-polyfills.ts_88cf45._.js:14:15]
      [at Object.<anonymous> (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_polyfill_app-polyfills.ts_88cf45._.js:17:3)]
      [at [next]/polyfill/app-polyfills.ts (ecmascript, ssr) (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_polyfill_app-polyfills.ts_88cf45._.js:35:3)]
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:496:21]
      [at runModuleExecutionHooks (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:542:3)]
      [at instantiateModule (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:494:3)]
      [at getOrInstantiateModuleFromParent (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:587:10)]
      [at esmImport (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:217:18)]
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_91f82d._.js:27:109]
      [at [next]/entry/app-renderer.tsx/(COMPONENT_0)/[project]/app/assignments/new/page.tsx (ecmascript, client chunks)/(COMPONENT_1)/[project]/app/layout.tsx (ecmascript, client chunks)/(METADATA_2)/[project]/app/favicon.ico/(IMAGE)/[project]/app/favicon.ico (static) (structured image object, ecmascript)/(BOOTSTRAP)/[next]/entry/app/hydrate.tsx (ecmascript, chunk group files) (ecmascript, ssr) (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_91f82d._.js:325:3)]
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:496:21]
      [at runModuleExecutionHooks (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:542:3)]
      [at instantiateModule (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:494:3)]
      [at getOrInstantiateRuntimeModule (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:1433:10)]
      [at Object.registerChunk (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:1538:11)]
      [at registerChunk (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:1497:18)]
      [at <anonymous>]
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:1587:18]
      [at Object.<anonymous> (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_43f03d._.js:1588:3)]
      [at Module._compile (node:internal/modules/cjs/loader:1159:14)]
      [at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)]
      [at Module.load (node:internal/modules/cjs/loader:1037:32)]
      [at Module._load (node:internal/modules/cjs/loader:878:12)]
      [at Module.require (node:internal/modules/cjs/loader:1061:19)]
      [at require (node:internal/modules/cjs/helpers:103:18)]
      [at Object.<anonymous> (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_6af326._.js:27:1)]
      [at Module._compile (node:internal/modules/cjs/loader:1159:14)]
      [at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)]
      [at Module.load (node:internal/modules/cjs/loader:1037:32)]
      [at Module._load (node:internal/modules/cjs/loader:878:12)]
      [at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)]
      [at node:internal/main/run_main_module:23:47]

Status: exit status: 0

Running npx next dev from within the actual app folder (apps/nextjs/) works fine though.

jridgewell commented 1 year ago

Hi @maltesa!

To confirm, can you do the following in your project:

cat node_modules/next/package.json
cat node_modules/next/dist/server/node-polyfill-fetch.js

I just want to ensure that the next package is in fact 13.4.*, which definitely has a node-polyfill-fetch.js file.

maltesa commented 1 year ago

Here it comes: cat node_modules/next/package.json

{
  "name": "next",
  "version": "13.4.1",
  "description": "The React Framework",
  "main": "./dist/server/next.js",
  "license": "MIT",
  "repository": "vercel/next.js",
  "bugs": "https://github.com/vercel/next.js/issues",
  "homepage": "https://nextjs.org",
  "types": "index.d.ts",
  "files": [
    "dist",
    "app.js",
    "app.d.ts",
    "babel.js",
    "babel.d.ts",
    "client.js",
    "client.d.ts",
    "compat",
    "cache.js",
    "cache.d.ts",
    "config.js",
    "config.d.ts",
    "constants.js",
    "constants.d.ts",
    "document.js",
    "document.d.ts",
    "dynamic.js",
    "dynamic.d.ts",
    "error.js",
    "error.d.ts",
    "future",
    "legacy",
    "script.js",
    "script.d.ts",
    "server.js",
    "server.d.ts",
    "head.js",
    "head.d.ts",
    "image.js",
    "image.d.ts",
    "link.js",
    "link.d.ts",
    "router.js",
    "router.d.ts",
    "jest.js",
    "jest.d.ts",
    "amp.js",
    "amp.d.ts",
    "index.d.ts",
    "types/index.d.ts",
    "types/global.d.ts",
    "types/compiled.d.ts",
    "image-types/global.d.ts",
    "navigation-types/navigation.d.ts",
    "navigation-types/compat/navigation.d.ts",
    "font",
    "navigation.js",
    "navigation.d.ts",
    "headers.js",
    "headers.d.ts",
    "navigation-types",
    "web-vitals.js",
    "web-vitals.d.ts"
  ],
  "bin": {
    "next": "./dist/bin/next"
  },
  "scripts": {
    "dev": "taskr",
    "release": "taskr release",
    "build": "pnpm release && pnpm types",
    "prepublishOnly": "cd ../../ && turbo run build",
    "types": "tsc --declaration --emitDeclarationOnly --stripInternal --declarationDir dist",
    "typescript": "tsec --noEmit",
    "ncc-compiled": "ncc cache clean && taskr ncc"
  },
  "taskr": {
    "requires": [
      "./taskfile-ncc.js",
      "./taskfile-swc.js",
      "./taskfile-watch.js"
    ]
  },
  "dependencies": {
    "@next/env": "13.4.1",
    "@swc/helpers": "0.5.1",
    "busboy": "1.6.0",
    "caniuse-lite": "^1.0.30001406",
    "postcss": "8.4.14",
    "styled-jsx": "5.1.1",
    "zod": "3.21.4"
  },
  "peerDependencies": {
    "@opentelemetry/api": "^1.1.0",
    "fibers": ">= 3.1.0",
    "node-sass": "^6.0.0 || ^7.0.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "sass": "^1.3.0"
  },
  "peerDependenciesMeta": {
    "node-sass": {
      "optional": true
    },
    "sass": {
      "optional": true
    },
    "fibers": {
      "optional": true
    },
    "@opentelemetry/api": {
      "optional": true
    }
  },
  "devDependencies": {
    "@ampproject/toolbox-optimizer": "2.8.3",
    "@babel/code-frame": "7.12.11",
    "@babel/core": "7.18.0",
    "@babel/eslint-parser": "7.18.2",
    "@babel/generator": "7.18.0",
    "@babel/plugin-proposal-class-properties": "7.14.5",
    "@babel/plugin-proposal-export-namespace-from": "7.14.5",
    "@babel/plugin-proposal-numeric-separator": "7.14.5",
    "@babel/plugin-proposal-object-rest-spread": "7.14.7",
    "@babel/plugin-syntax-bigint": "7.8.3",
    "@babel/plugin-syntax-dynamic-import": "7.8.3",
    "@babel/plugin-syntax-import-assertions": "7.16.7",
    "@babel/plugin-syntax-jsx": "7.14.5",
    "@babel/plugin-transform-modules-commonjs": "7.18.0",
    "@babel/plugin-transform-runtime": "7.18.0",
    "@babel/preset-env": "7.18.0",
    "@babel/preset-react": "7.14.5",
    "@babel/preset-typescript": "7.17.12",
    "@babel/runtime": "7.15.4",
    "@babel/traverse": "7.18.0",
    "@babel/types": "7.18.0",
    "@capsizecss/metrics": "1.1.0",
    "@edge-runtime/cookies": "3.0.6",
    "@edge-runtime/primitives": "2.1.2",
    "@hapi/accept": "5.0.2",
    "@jest/transform": "29.5.0",
    "@jest/types": "29.5.0",
    "@napi-rs/cli": "2.14.7",
    "@napi-rs/triples": "1.1.0",
    "@next/polyfill-module": "13.4.1",
    "@next/polyfill-nomodule": "13.4.1",
    "@next/react-dev-overlay": "13.4.1",
    "@next/react-refresh-utils": "13.4.1",
    "@next/swc": "13.4.1",
    "@opentelemetry/api": "1.4.1",
    "@segment/ajv-human-errors": "2.1.2",
    "@taskr/clear": "1.1.0",
    "@taskr/esnext": "1.1.0",
    "@types/amphtml-validator": "1.0.0",
    "@types/babel__code-frame": "7.0.2",
    "@types/babel__core": "7.1.12",
    "@types/babel__generator": "7.6.2",
    "@types/babel__template": "7.4.0",
    "@types/babel__traverse": "7.11.0",
    "@types/bytes": "3.1.1",
    "@types/ci-info": "2.0.0",
    "@types/compression": "0.0.36",
    "@types/content-disposition": "0.5.4",
    "@types/content-type": "1.1.3",
    "@types/cookie": "0.3.3",
    "@types/cross-spawn": "6.0.0",
    "@types/debug": "4.1.5",
    "@types/express-serve-static-core": "4.17.33",
    "@types/fresh": "0.5.0",
    "@types/glob": "7.1.1",
    "@types/jsonwebtoken": "9.0.0",
    "@types/lodash": "4.14.149",
    "@types/lodash.curry": "4.1.6",
    "@types/lru-cache": "5.1.0",
    "@types/micromatch": "4.0.2",
    "@types/node-fetch": "2.6.1",
    "@types/path-to-regexp": "1.7.0",
    "@types/platform": "1.3.4",
    "@types/react": "18.2.5",
    "@types/react-dom": "18.2.3",
    "@types/react-is": "17.0.3",
    "@types/semver": "7.3.1",
    "@types/send": "0.14.4",
    "@types/shell-quote": "1.7.1",
    "@types/tar": "4.0.3",
    "@types/text-table": "0.2.1",
    "@types/ua-parser-js": "0.7.36",
    "@types/uuid": "8.3.1",
    "@types/webpack-sources1": "npm:@types/webpack-sources@0.1.5",
    "@types/ws": "8.2.0",
    "@vercel/ncc": "0.34.0",
    "@vercel/nft": "0.22.6",
    "acorn": "8.5.0",
    "ajv": "8.11.0",
    "amphtml-validator": "1.0.35",
    "anser": "1.4.9",
    "arg": "4.1.0",
    "assert": "2.0.0",
    "async-retry": "1.2.3",
    "async-sema": "3.0.0",
    "babel-plugin-transform-define": "2.0.0",
    "babel-plugin-transform-react-remove-prop-types": "0.4.24",
    "browserify-zlib": "0.2.0",
    "browserslist": "4.20.2",
    "buffer": "5.6.0",
    "bytes": "3.1.1",
    "chalk": "2.4.2",
    "ci-info": "watson/ci-info#f43f6a1cefff47fb361c88cf4b943fdbcaafe540",
    "cli-select": "1.1.2",
    "client-only": "0.0.1",
    "comment-json": "3.0.3",
    "compression": "1.7.4",
    "conf": "5.0.0",
    "constants-browserify": "1.0.0",
    "content-disposition": "0.5.3",
    "content-type": "1.0.4",
    "cookie": "0.4.1",
    "cross-spawn": "7.0.3",
    "crypto-browserify": "3.12.0",
    "css.escape": "1.5.1",
    "cssnano-preset-default": "5.2.14",
    "data-uri-to-buffer": "3.0.1",
    "debug": "4.1.1",
    "devalue": "2.0.1",
    "domain-browser": "4.19.0",
    "edge-runtime": "2.1.4",
    "events": "3.3.0",
    "find-cache-dir": "3.3.1",
    "find-up": "4.1.0",
    "fresh": "0.5.2",
    "get-orientation": "1.1.2",
    "glob": "7.1.7",
    "gzip-size": "5.1.1",
    "http-proxy": "1.18.1",
    "http-proxy-agent": "5.0.0",
    "https-browserify": "1.0.0",
    "https-proxy-agent": "5.0.1",
    "icss-utils": "5.1.0",
    "ignore-loader": "0.1.2",
    "image-size": "1.0.0",
    "is-docker": "2.0.0",
    "is-wsl": "2.2.0",
    "jest-worker": "27.0.0-next.5",
    "json5": "2.2.3",
    "jsonwebtoken": "9.0.0",
    "loader-runner": "4.3.0",
    "loader-utils2": "npm:loader-utils@2.0.0",
    "loader-utils3": "npm:loader-utils@3.1.3",
    "lodash.curry": "4.1.1",
    "lru-cache": "5.1.1",
    "micromatch": "4.0.4",
    "mini-css-extract-plugin": "2.4.3",
    "nanoid": "3.1.32",
    "native-url": "0.3.4",
    "neo-async": "2.6.1",
    "node-fetch": "2.6.7",
    "node-html-parser": "5.3.3",
    "ora": "4.0.4",
    "os-browserify": "0.3.0",
    "p-limit": "3.1.0",
    "path-browserify": "1.0.1",
    "path-to-regexp": "6.1.0",
    "platform": "1.3.6",
    "postcss-flexbugs-fixes": "5.0.2",
    "postcss-modules-extract-imports": "3.0.0",
    "postcss-modules-local-by-default": "4.0.0",
    "postcss-modules-scope": "3.0.0",
    "postcss-modules-values": "4.0.0",
    "postcss-preset-env": "7.4.3",
    "postcss-safe-parser": "6.0.0",
    "postcss-scss": "4.0.3",
    "postcss-value-parser": "4.2.0",
    "process": "0.11.10",
    "punycode": "2.1.1",
    "querystring-es3": "0.2.1",
    "raw-body": "2.4.1",
    "react-is": "18.2.0",
    "react-refresh": "0.12.0",
    "regenerator-runtime": "0.13.4",
    "sass-loader": "12.4.0",
    "schema-utils2": "npm:schema-utils@2.7.1",
    "schema-utils3": "npm:schema-utils@3.0.0",
    "semver": "7.3.2",
    "send": "0.17.1",
    "server-only": "0.0.1",
    "setimmediate": "1.0.5",
    "shell-quote": "1.7.3",
    "source-map": "0.6.1",
    "stacktrace-parser": "0.1.10",
    "stream-browserify": "3.0.0",
    "stream-http": "3.1.1",
    "string-hash": "1.1.3",
    "string_decoder": "1.3.0",
    "strip-ansi": "6.0.0",
    "tar": "6.1.11",
    "taskr": "1.1.0",
    "terser": "5.14.1",
    "text-table": "0.2.0",
    "timers-browserify": "2.0.12",
    "tty-browserify": "0.0.1",
    "ua-parser-js": "0.7.28",
    "undici": "5.22.0",
    "unistore": "3.4.1",
    "util": "0.12.4",
    "uuid": "8.3.2",
    "vm-browserify": "1.1.2",
    "watchpack": "2.4.0",
    "web-vitals": "3.0.0",
    "webpack": "5.74.0",
    "webpack-sources1": "npm:webpack-sources@1.4.3",
    "webpack-sources3": "npm:webpack-sources@3.2.3",
    "ws": "8.2.3"
  },
  "resolutions": {
    "browserslist": "4.20.2",
    "caniuse-lite": "1.0.30001406"
  },
  "engines": {
    "node": ">=16.8.0"
  },
  "optionalDependencies": {
    "@next/swc-darwin-arm64": "13.4.1",
    "@next/swc-darwin-x64": "13.4.1",
    "@next/swc-linux-arm64-gnu": "13.4.1",
    "@next/swc-linux-arm64-musl": "13.4.1",
    "@next/swc-linux-x64-gnu": "13.4.1",
    "@next/swc-linux-x64-musl": "13.4.1",
    "@next/swc-win32-arm64-msvc": "13.4.1",
    "@next/swc-win32-ia32-msvc": "13.4.1",
    "@next/swc-win32-x64-msvc": "13.4.1"
  }
}

and cat node_modules/next/dist/server/node-polyfill-fetch.js

// TODO: Remove use of `any` type.
// Polyfill fetch() in the Node.js environment
"use strict";
if (!global.fetch) {
    function getFetchImpl() {
        return require("next/dist/compiled/undici");
    }
    function getRequestImpl() {
        const OriginRequest = getFetchImpl().Request;
        return class Request extends OriginRequest {
            constructor(input, init){
                super(input, init);
                this.next = init == null ? void 0 : init.next;
            }
        };
    }
    global.fetch = (...args)=>{
        var _global___NEXT_HTTP_AGENT_OPTIONS;
        const fetchImpl = getFetchImpl();
        // Undici does not support the `keepAlive` option,
        // instead we have to pass a custom dispatcher
        if (!((_global___NEXT_HTTP_AGENT_OPTIONS = global.__NEXT_HTTP_AGENT_OPTIONS) == null ? void 0 : _global___NEXT_HTTP_AGENT_OPTIONS.keepAlive) && !global.__NEXT_UNDICI_AGENT_SET) {
            global.__NEXT_UNDICI_AGENT_SET = true;
            fetchImpl.setGlobalDispatcher(new fetchImpl.Agent({
                pipelining: 0
            }));
            console.warn('Warning - Configuring `keepAlive: false` is deprecated. Use `{ headers: { connection: "close" } }` instead.');
        }
        return fetchImpl.fetch(...args);
    };
    Object.defineProperties(global, {
        Headers: {
            get () {
                return getFetchImpl().Headers;
            }
        },
        Request: {
            get () {
                return getRequestImpl();
            }
        },
        Response: {
            get () {
                return getFetchImpl().Response;
            }
        }
    });
}

//# sourceMappingURL=node-polyfill-fetch.js.map

Update. Just to make sure. This is the error I get:

Error: Cannot find module 'next/dist/server/node-polyfill-fetch'

Debug info:
- Error: Cannot find module 'next/dist/server/node-polyfill-fetch'
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_polyfill_app-polyfills.ts_88cf45._.js:14:15]
      [at Object.<anonymous> (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_polyfill_app-polyfills.ts_88cf45._.js:17:3)]
      [at [next]/polyfill/app-polyfills.ts (ecmascript, ssr) (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_polyfill_app-polyfills.ts_88cf45._.js:35:3)]
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:496:21]
      [at runModuleExecutionHooks (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:542:3)]
      [at instantiateModule (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:494:3)]
      [at getOrInstantiateModuleFromParent (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:587:10)]
      [at esmImport (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:217:18)]
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_91f82d._.js:27:109]
      [at [next]/entry/app-renderer.tsx/(COMPONENT_0)/[project]/app/assignments/new/page.tsx (ecmascript, client chunks)/(COMPONENT_1)/[project]/app/layout.tsx (ecmascript, client chunks)/(METADATA_2)/[project]/app/favicon.ico/(IMAGE)/[project]/app/favicon.ico (static) (structured image object, ecmascript)/(BOOTSTRAP)/[next]/entry/app/hydrate.tsx (ecmascript, chunk group files) (ecmascript, ssr) (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_91f82d._.js:325:3)]
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:496:21]
      [at runModuleExecutionHooks (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:542:3)]
      [at instantiateModule (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:494:3)]
      [at getOrInstantiateRuntimeModule (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:1433:10)]
      [at Object.registerChunk (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:1538:11)]
      [at registerChunk (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:1497:18)]
      [at <anonymous>]
      [at /workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:1587:18]
      [at Object.<anonymous> (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_3c66ba._.js:1588:3)]
      [at Module._compile (node:internal/modules/cjs/loader:1159:14)]
      [at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)]
      [at Module.load (node:internal/modules/cjs/loader:1037:32)]
      [at Module._load (node:internal/modules/cjs/loader:878:12)]
      [at Module.require (node:internal/modules/cjs/loader:1061:19)]
      [at require (node:internal/modules/cjs/helpers:103:18)]
      [at Object.<anonymous> (/workspace/apps/nextjs/.next/server/app/chunks/ssr/[next]_entry_app-renderer.tsx_6af326._.js:27:1)]
      [at Module._compile (node:internal/modules/cjs/loader:1159:14)]
      [at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)]
      [at Module.load (node:internal/modules/cjs/loader:1037:32)]
      [at Module._load (node:internal/modules/cjs/loader:878:12)]
      [at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)]
      [at node:internal/main/run_main_module:23:47]

Status: exit status: 0
biocomputer924 commented 1 year ago

This problem occurs when the module does not exist in node_modules directly under the workspace.

npm, yarn, or pnpm will place modules in node_modules in the "workspace root", but will not search the workspace's ancestor directories when turbo mode is enabled.

I don't know if it is a Turbopack or next-swc issue, but there is a problem with module resolution algorism.

jb-thery commented 1 year ago

I have the same issue on my turbo monorepo with : "next": "^13.4.2" "turbo": "^1.9.4"

Here is my dev command in my apps folder :

"dev": "next dev --turbo",

Here is my global dev command :

"dev": "turbo dev --filter myApp",
zsherman commented 1 year ago

Also running into this issue with next@13.4.2 and turbo@1.9.6

bszymkow commented 1 year ago

interestingly, "next/dist/server/node-polyfill.fetch.d.ts " exists but is an empty file. do we know if this is intended? (next 13.4.3)

padmaia commented 1 year ago

Sorry folks, I thought this was fixed with 13.4.0, but it looks definitely fixed with 13.4.4 now.

quocanhbk commented 1 year ago

I still encounter this problem with yarn workspace and next@13.4.7

image

mertthesamael commented 1 year ago

Still having this issue when trying to run "next dev --turbo" with pnpm.

I'm using NextJS 13.4.12. Here's the full log :

Error: Cannot find module 'next/dist/server/node-polyfill-fetch'

Debug info:
- Error: Cannot find module 'next/dist/server/node-polyfill-fetch'
      [at C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_polyfill_app-polyfills_ts_fa7482._.js:14:15]
      [at Object.<anonymous> (C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_polyfill_app-polyfills_ts_fa7482._.js:17:3)]
      [at [next]/polyfill/app-polyfills.ts (ecmascript, ssr) (C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_polyfill_app-polyfills_ts_fa7482._.js:41:3)]
      at /turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:320:21 [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:390:27]
      at runModuleExecutionHooks (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:370:5) [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:424:9]
      at instantiateModule (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:319:5) [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:389:9]
      at getOrInstantiateModuleFromParent (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:418:10) [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:451:12]
      at esmImport (/turbopack/[turbopack]/shared/runtime-utils.ts:203:18) [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:102:20]
      [at C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_911aa9._.js:123:109]
      [at [next]/entry/app-renderer.tsx/(APP_ENTRY)/[next]/entry/app-entry.tsx/(COMPONENT_0)/[project]/app/page.tsx (ecmascript, client chunks, with chunking context scope)/(COMPONENT_1)/[project]/app/layout.tsx (ecmascript, client chunks, with chunking context scope)/(METADATA_2)/[project]/app/favicon.ico.mjs/(IMAGE)/[project]/app/favicon.ico (static) (structured image object, ecmascript) (ecmascript, client chunks, with chunking context scope)/(APP_BOOTSTRAP)/[next]/entry/app/hydrate.tsx (ecmascript, chunk group files) (ecmascript, ssr) (C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_911aa9._.js:281:3)]
      at /turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:320:21 [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:390:27]
      at runModuleExecutionHooks (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:370:5) [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:424:9]
      at instantiateModule (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:319:5) [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:389:9]
      at getOrInstantiateRuntimeModule (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:1276:10) [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:997:12]
      at Object.registerChunk (/turbopack/[turbopack]/dev/runtime/nodejs/runtime-backend-nodejs.ts:49:11) [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:1096:21]
      at registerChunk (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:1337:18) [C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:1037:20]
      [at <anonymous>]
      [at C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:1133:18]
      [at Object.<anonymous> (C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_21b079._.js:1134:3)]
      [at Module._compile (node:internal/modules/cjs/loader:1254:14)]
      [at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)]
      [at Module.load (node:internal/modules/cjs/loader:1117:32)]
      [at Module._load (node:internal/modules/cjs/loader:958:12)]
      [at Module.require (node:internal/modules/cjs/loader:1141:19)]
      [at require (node:internal/modules/cjs/helpers:110:18)]
      [at Object.<anonymous> (C:\Users\merte\OneDrive\Belgeler\Folders\Code\backyard-landing\.next\server\app\chunks\ssr\[next]_entry_app-renderer_tsx_3dbc50._.js:19:1)]
      [at Module._compile (node:internal/modules/cjs/loader:1254:14)]
      [at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)]
      [at Module.load (node:internal/modules/cjs/loader:1117:32)]
      [at Module._load (node:internal/modules/cjs/loader:958:12)]
      [at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)]
      [at node:internal/main/run_main_module:23:47]

Status: exit code: 1
lpbonomi commented 1 year ago

Me too in 13.4.19:

error -
  [rendering]
    [root of the server]/home
      Error during SSR Rendering
      Error: Cannot find module 'next/dist/server/node-polyfill-fetch'

      Debug info:
      - Error: Cannot find module 'next/dist/server/node-polyfill-fetch'
            [at /Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_polyfill_app-polyfills_ts_4b5203._.js:14:15]
            [at Object.<anonymous> (/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_polyfill_app-polyfills_ts_4b5203._.js:17:3)]
            [at [next]/polyfill/app-polyfills.ts (ecmascript, ssr) (/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_polyfill_app-polyfills_ts_4b5203._.js:41:3)]
            at /turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:322:21 [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:394:27]
            at runModuleExecutionHooks (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:374:5) [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:427:9]
            at instantiateModule (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:321:5) [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:393:9]
            at getOrInstantiateModuleFromParent (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:422:10) [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:454:12]
            at esmImport (/turbopack/[turbopack]/shared/runtime-utils.ts:203:18) [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:102:20]
            [at /Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_e8553a._.js:123:109]
            [at [next]/entry/app-renderer.tsx/(APP_ENTRY)/[next]/entry/app-entry.tsx/(COMPONENT_0)/[project]/app/home/page.tsx (ecmascript, client chunks, with chunking context scope)/(COMPONENT_1)/[project]/app/error.js (ecmascript, client chunks, with chunking context scope)/(COMPONENT_2)/[project]/app/layout.tsx (ecmascript, client chunks, with chunking context scope)/(COMPONENT_3)/[project]/app/not-found.tsx (ecmascript, client chunks, with chunking context scope) (ecmascript, client chunks, with chunking context scope)/(APP_BOOTSTRAP)/[next]/entry/app/hydrate.tsx (ecmascript, chunk group files) (ecmascript, ssr) (/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_e8553a._.js:281:3)]
            at /turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:322:21 [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:394:27]
            at runModuleExecutionHooks (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:374:5) [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:427:9]
            at instantiateModule (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:321:5) [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:393:9]
            at getOrInstantiateRuntimeModule (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:1280:10) [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:1000:12]
            at Object.registerChunk (/turbopack/[turbopack]/dev/runtime/nodejs/runtime-backend-nodejs.ts:85:11) [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:1141:21]
            at registerChunk (/turbopack/[turbopack]/dev/runtime/base/runtime-base.ts:1341:18) [/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:1040:20]
            [at <anonymous>]
            [at /Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:1165:18]
            [at Object.<anonymous> (/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_99c31c._.js:1166:3)]
            [at Module._compile (node:internal/modules/cjs/loader:1241:14)]
            [at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)]
            [at Module.load (node:internal/modules/cjs/loader:1091:32)]
            [at Module._load (node:internal/modules/cjs/loader:938:12)]
            [at Module.require (node:internal/modules/cjs/loader:1115:19)]
            [at require (node:internal/modules/helpers:130:18)]
            [at Object.<anonymous> (/Users/luispe/Repos/ultradrop-app/apps/frontend/.next/server/app/chunks/ssr/[next]_entry_app-renderer_tsx_2130a1._.js:38:1)]
            [at Module._compile (node:internal/modules/cjs/loader:1241:14)]
            [at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)]
            [at Module.load (node:internal/modules/cjs/loader:1091:32)]
            [at Module._load (node:internal/modules/cjs/loader:938:12)]
            [at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)]
            [at node:internal/main/run_main_module:23:47]

  [resolve]
rflihxyz commented 6 months ago

Same issue here