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

next dev and next build broken on Yarn PnP in the latest release #32115

Closed
brc-dd opened this issue Dec 4, 2021 · 19 comments · Fixed by #33236
Closed

next dev and next build broken on Yarn PnP in the latest release #32115

brc-dd opened this issue Dec 4, 2021 · 19 comments · Fixed by #33236

Comments

@brc-dd
Copy link

brc-dd commented Dec 4, 2021

What version of Next.js are you using?

v12.0.5

What version of Node.js are you using?

v16.13.1

What browser are you using?

N/A

What operating system are you using?

Windows 11 (Build 22509.1000)

How are you deploying your application?

yarn next build && yarn next start

Describe the Bug

Getting the following errors on running yarn next build:

$ yarn next build
info  - Checking validity of types
warn  - No ESLint configuration detected. Run next lint to begin setup
info  - Creating an optimized production build
Failed to compile.

./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/index.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\client\index.js

Caused by:
    The system cannot find the path specified. (os error 3)

Import trace for requested module:
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/next.js

./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/request-idle-callback.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\client\request-idle-callback.js

Caused by:
    The system cannot find the path specified. (os error 3)

Import trace for requested module:
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/route-loader.js
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/shared/lib/router/router.js
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/router.js

./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/pages/_app.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\pages\_app.js

Caused by:
    The system cannot find the path specified. (os error 3)

./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/shared/lib/head.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\shared\lib\head.js

Caused by:
    The system cannot find the path specified. (os error 3)

Import trace for requested module:
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/pages/_error.js

./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/shared/lib/mitt.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\shared\lib\mitt.js

Caused by:
    The system cannot find the path specified. (os error 3)

Import trace for requested module:
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/shared/lib/router/router.js
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/router.js


> Build failed because of webpack errors

The issue seems to be SWC related. After creating .babelrc with next/babel preset, the yarn next build command is working but yarn next dev is still throwing error.

Also, why the Checking validity of types log is shown even if someone is not using TS?

Expected Behavior

To build successfully and start as happens in next@12.0.4.

To Reproduce

mkdir foo && cd "$_"
yarn init -2
yarn add next react react-dom
mkdir pages
echo 'export default () => <div>Hello World</div>' > pages/index.js
yarn next build

Based on https://github.com/yarnpkg/berry/blob/master/.github/workflows/e2e-next-workflow.yml

@brc-dd brc-dd added the bug Issue was opened via the bug report template. label Dec 4, 2021
@brc-dd brc-dd changed the title Latest build broken on Yarn PnP next dev and next build broken on Yarn PnP in the latest release Dec 4, 2021
@timneutkens timneutkens added area: Yarn PnP / pnpm and removed bug Issue was opened via the bug report template. labels Dec 4, 2021
@timneutkens
Copy link
Member

Can you try setting:

module.exports = {
  experimental: {
    swcFileReading: false
  }
}

@brc-dd
Copy link
Author

brc-dd commented Dec 4, 2021

@timneutkens next build is working after setting that, but next dev is still throwing errors:

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn  - You have enabled experimental feature(s).
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use them at your own risk.

error - ./.yarn/__virtual__/react-dom-virtual-7a7367685f/0/cache/react-dom-npm-17.0.2-f551215af1-1c1eaa3bca.zip/node_modules/react-dom/cjs/react-dom.development.js
Module build failed: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type number (-2147483514)
    at new Promise (<anonymous>)
wait  - compiling...
error - ./.yarn/__virtual__/react-dom-virtual-7a7367685f/0/cache/react-dom-npm-17.0.2-f551215af1-1c1eaa3bca.zip/node_modules/react-dom/cjs/react-dom.development.js
Module build failed: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type number (-2147483418)
    at new Promise (<anonymous>)
wait  - compiling...
error - ./.yarn/__virtual__/react-dom-virtual-7a7367685f/0/cache/react-dom-npm-17.0.2-f551215af1-1c1eaa3bca.zip/node_modules/react-dom/cjs/react-dom.development.js
Module build failed: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type number (-2147483418)
    at new Promise (<anonymous>)
(node:13216) [DEP_WEBPACK_MODULE_ISSUER] DeprecationWarning: Module.issuer: Use new ModuleGraph API
(Use `node --trace-deprecation ...` to show where the warning was created)
wait  - compiling /_error (client and server)...
error - ./.yarn/__virtual__/react-dom-virtual-7a7367685f/0/cache/react-dom-npm-17.0.2-f551215af1-1c1eaa3bca.zip/node_modules/react-dom/cjs/react-dom.development.js
Module build failed: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type number (-2147483418)
    at new Promise (<anonymous>)
error - Error: Qualified path resolution failed - none of those files can be found on the disk.

Source path: C:\Users\brc-dd\Desktop\foo\.next\fallback-build-manifest.json
Not found: C:\Users\brc-dd\Desktop\foo\.next\fallback-build-manifest.json
Not found: C:\Users\brc-dd\Desktop\foo\.next\fallback-build-manifest.json.js
Not found: C:\Users\brc-dd\Desktop\foo\.next\fallback-build-manifest.json.json
Not found: C:\Users\brc-dd\Desktop\foo\.next\fallback-build-manifest.json.node

Require stack:
- C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\server\load-components.js
- C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\build\utils.js
- C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\build\output\store.js
- C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\build\output\index.js
- C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\cli\next-dev.js
- C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\bin\next
    at Function.external_module_.Module._resolveFilename (C:\Users\brc-dd\Desktop\foo\.pnp.cjs:13363:55)
    at Function.mod._resolveFilename (C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\build\webpack\require-hook.js:171:28)
    at Function.external_module_.Module._load (C:\Users\brc-dd\Desktop\foo\.pnp.cjs:13162:48)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.loadDefaultErrorComponents (C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\server\load-components.js:22:24)
    at DevServer.getFallbackErrorComponents (C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\server\dev\next-dev-server.js:679:43)
    at async DevServer.renderErrorToResponse (C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\server\next-server.js:1738:40)
    at async pipe.req.req (C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\server\next-server.js:1678:30)
    at async DevServer.pipe (C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\server\next-server.js:1156:25)

PS: This is happening since v12.0.5-canary.0.

Related Issues - #31552, #31812

@dlindenkreuz
Copy link
Contributor

dlindenkreuz commented Dec 9, 2021

This prevents me from using Next.js >= v12.0.5.

Edit: node v16.13.1, macOS 12.0.1

@amuttsch
Copy link

amuttsch commented Dec 13, 2021

The issue is still happening with v12.0.8-canary.4. Setting swcFileReading: false fixes the Error: Failed to read source code error, but it triggers the following error instead:

info  - Creating an optimized production build  
Failed to compile.

./.yarn/__virtual__/react-query-virtual-b938dbb86e/0/cache/react-query-npm-3.34.2-955c5a58c3-c2cb423cae.zip/node_modules/react-query/es/core/types.js
Module build failed: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type number (-2147483201)
    at Object.readFile (node:fs:393:10)
    at .../.pnp.cjs:32872:19
    at new Promise (<anonymous>)
    at NodeFS.readFilePromise (.../.pnp.cjs:32870:18)
    at makeCallPromise.async.subPath.subPath (.../.pnp.cjs:35838:36)
    at ZipOpenFS.makeCallPromise (.../.pnp.cjs:35960:45)
    at ZipOpenFS.readFilePromise (.../.pnp.cjs:35831:17)
    at VirtualFS.readFilePromise (.../.pnp.cjs:33182:26)
    at PosixFS.readFilePromise (.../.pnp.cjs:33182:26)
    at URLFS.readFilePromise (.../.pnp.cjs:33182:26)

Not quite sure why react query is unhappy, but I guess it sth. with the bundle process seems wrong.

I also have the esmExternals: false option set is this is somehow related.

I created an example repo here: https://github.com/amuttsch/next-pnp-error

@brc-dd
Copy link
Author

brc-dd commented Dec 13, 2021

For now, if anyone is facing the issue with next dev, try unplugging react-dom (yarn unplug react-dom), it should work (although in a way this defeats the purpose of zero-installs).

@amuttsch
Copy link

@brc-dd Thanks for the hint, unplugging react query "fixes" my error above. But I agree, unplugging should not be the solution for this issue. I'm staying on 12.0.5 for now until we have a proper fix :-)

@reckter
Copy link

reckter commented Dec 22, 2021

I needed to unplug next itself for it to work with the newest version (12.0.7).

Edit: A fluke on my part, react-dom was needed in the end

@kaptcha0
Copy link

Version 12.0.4 is the highest version I could go without this error.

@kaykdm kaykdm mentioned this issue Dec 28, 2021
10 tasks
@kaykdm
Copy link
Contributor

kaykdm commented Dec 28, 2021

@timneutkens @sokra

next build is working after setting that, but next dev is still throwing errors:

I just opened PR to fix this
#32867

kodiakhq bot pushed a commit that referenced this issue Jan 11, 2022
x-ref [#31552 ](#31552)
x-ref #32115
x-ref #32546
x-ref #32721

Since this PR #31455 is merged, `enhanced-resolve` dependency's resolved field is changed which caused broken yarn pnp.
I am not sure how this field has been changed or this is intentional or not 
When I install webpack locally, `enhanced-resolve`'s resolved field in lock file is always `registry.yarnpkg.com` not `codeload.github.com`

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
@taavisalo
Copy link

Still broken with latest 12.0.8. yarn dev throws "Failed to read source code" errors.

@kaykdm
Copy link
Contributor

kaykdm commented Jan 12, 2022

Still broken with latest 12.0.8. yarn dev throws "Failed to read source code" errors.

@taavisalo
see here: #32867 (comment)

@taavisalo
Copy link

taavisalo commented Jan 12, 2022

Still broken with latest 12.0.8. yarn dev throws "Failed to read source code" errors.

@taavisalo see here: #32867 (comment)

Thank you! Running yarn cache clear fixed the problem.

EDIT: yarn dev works, but yarn build still fails with "Error: Failed to read source code" errors.

@amuttsch
Copy link

@taavisalo Have you added swcFileReading: false, to experimental? Setting it in the root object doesn't work, but in experimental I was able to fix this issue.

@taavisalo
Copy link

@taavisalo Have you added swcFileReading: false, to experimental? Setting it in the root object doesn't work, but in experimental I was able to fix this issue.

This worked. Probably going to have to stick with 12.0.4 still, because current solution requires enabling experimental features.

@rtritto
Copy link

rtritto commented Jan 12, 2022

This issue is similar to #31552 (fixed with #32867) and should be closed.
Last issue is #31812 (temporary fixed with workaround of swcFileReading: false in experimental).

@dgattey
Copy link

dgattey commented Jan 18, 2022

Hmm, with 12.0.8 this is still broken for me, when running next dev or next build. If I set swcFileReading to false in my next.config.js, it works. Should setting that experimental flag still be necessary to get Yarn PnP to work on 12.0.8?

@balazsorban44
Copy link
Member

@dgattey that option has been recently changed to accommodate your use case in #33236 we will include it in the next upcoming canary release (which is 🔜™️), thanks for the feedback! 👍

@zigang93
Copy link

zigang93 commented Jan 21, 2022

my yarn build seem like stuck at info - Checking validity of types. anyone encounter same issue like me?

with swcFileReading: false in experimental

next.js version : 12.0.8

natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
x-ref [vercel#31552 ](vercel#31552)
x-ref vercel#32115
x-ref vercel#32546
x-ref vercel#32721

Since this PR vercel#31455 is merged, `enhanced-resolve` dependency's resolved field is changed which caused broken yarn pnp.
I am not sure how this field has been changed or this is intentional or not 
When I install webpack locally, `enhanced-resolve`'s resolved field in lock file is always `registry.yarnpkg.com` not `codeload.github.com`

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.