next.js: Error: Failed to read source code from `amp-dev.js`

What version of Next.js are you using?

12.0.5-canary.10-12.0.8

What version of Node.js are you using?

14.17.0

What browser are you using?

Not relevant

What operating system are you using?

Windows

How are you deploying your application?

Not relevant

Describe the Bug

I updated next.js from v12.0.5-canary.9 to v12.0.5-canary.10 and I got a file not found error of amp-dev.js.

Expected Behavior

No error.

To Reproduce

  1. yarn init -y
  2. yarn set version canary
  3. yarn add next@canary react react-dom
  4. Create pages folder
  5. yarn next
  6. Read log:
(node:14180) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
error - ./.yarn/__virtual__/next-virtual-553eee263b/0/cache/next-npm-12.0.5-canary.10-1a75536391-cbd811bead.zip/node_modules/next/dist/client/dev/amp-dev.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-553eee263b\0\cache\next-npm-12.0.5-canary.10-1a75536391-cbd811bead.zip\node_modules\next\dist\client\dev\amp-dev.js       

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-553eee263b/0/cache/next-npm-12.0.5-canary.10-1a75536391-cbd811bead.zip/node_modules/next/dist/client/dev/amp-dev.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-553eee263b\0\cache\next-npm-12.0.5-canary.10-1a75536391-cbd811bead.zip\node_modules\next\dist\client\dev\amp-dev.js       

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-553eee263b/0/cache/next-npm-12.0.5-canary.10-1a75536391-cbd811bead.zip/node_modules/next/dist/client/dev/amp-dev.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-553eee263b\0\cache\next-npm-12.0.5-canary.10-1a75536391-cbd811bead.zip\node_modules\next\dist\client\dev\amp-dev.js       

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 17 (6 by maintainers)

Most upvoted comments

This issue will be fixed with #33236

In next.js v12.0.5-canary.14, it’s fixed adding in next.config.js file:

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

This issue, should be fixed with #31995 (already merged in canary branch). Waiting release of next.js v12.0.5-canary.14 to test.

This issue persists with all latest yarn versions (currently 3.1.1 and 3.2.0-rc.6)

Did you not have this issue on v12.0.5-canary.9?

Maybe it works (bug #31552 blocks compiling after this issue is solved)

Without swcFileReading: false, it still persists with random output errors:

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
error - ./.yarn/__virtual__/next-virtual-c649e2e81d/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/dev/amp-dev.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-c649e2e81d\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\dev\amp-dev.js

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-c649e2e81d/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/dev/webpack-hot-middleware-client.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-c649e2e81d\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\dev\webpack-hot-middleware-client.js

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-c649e2e81d/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/dev/webpack-hot-middleware-client.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-c649e2e81d\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\dev\webpack-hot-middleware-client.js

Caused by:
    The system cannot find the path specified. (os error 3)
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
error - ./.yarn/__virtual__/next-virtual-510b9827f9/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/dev/amp-dev.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-510b9827f9\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\dev\amp-dev.js

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-510b9827f9/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/index.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-510b9827f9\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\index.js

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-510b9827f9/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/index.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-510b9827f9\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\index.js

Caused by:
    The system cannot find the path specified. (os error 3)
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
error - ./.yarn/__virtual__/next-virtual-c649e2e81d/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/dev/error-overlay/hot-dev-client.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-c649e2e81d\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\dev\error-overlay\hot-dev-client.js

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-c649e2e81d/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/portal/index.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-c649e2e81d\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\portal\index.js

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-c649e2e81d/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/portal/index.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-c649e2e81d\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\portal\index.js

Caused by:
    The system cannot find the path specified. (os error 3)
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
error - ./.yarn/__virtual__/next-virtual-c649e2e81d/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-c649e2e81d\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\client\dev\error-overlay\format-webpack-messages.js

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-c649e2e81d/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/shared/lib/i18n/normalize-locale-path.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-c649e2e81d\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\shared\lib\i18n\normalize-locale-path.js

Caused by:
    The system cannot find the path specified. (os error 3)
wait  - compiling...
error - ./.yarn/__virtual__/next-virtual-c649e2e81d/0/cache/next-npm-12.0.8-aa55acca00-947f0295aa.zip/node_modules/next/dist/shared/lib/i18n/normalize-locale-path.js
Error: Failed to read source code from C:\test-nextjs\.yarn\__virtual__\next-virtual-c649e2e81d\0\cache\next-npm-12.0.8-aa55acca00-947f0295aa.zip\node_modules\next\dist\shared\lib\i18n\normalize-locale-path.js

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

I’m keeping this issue opened because of the temporary workaround with swcFileReading.

This sounds like the problematic commit: https://github.com/vercel/next.js/pull/31682

cc @sokra

I suspect this is caused by Next reading files on the wasm/rust side rather than JS. It means it doesn’t go through the layer Yarn puts in place so that dependencies can be accessed directly from their zip archives.

The simplest fix preserving the intent would be for Next to fallback to using the fs.readFileSync method if it detects .yarn in the file path.

I tried setting nodeLinker back to node-modules and that was a workaround. But also loading time went x100 because of that. So hopefully the fixes they are pushing will fix these issues so we can use yarn pnp 😃