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

Error: Failed to read source code from amp-dev.js #31812

Closed
rtritto opened this issue Nov 25, 2021 · 17 comments · Fixed by #33236
Closed

Error: Failed to read source code from amp-dev.js #31812

rtritto opened this issue Nov 25, 2021 · 17 comments · Fixed by #33236

Comments

@rtritto
Copy link

rtritto commented Nov 25, 2021

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)
@rtritto
Copy link
Author

rtritto commented Nov 25, 2021

It should depend on changes in #31772 or #31759.

Edit:
I did a log of:

const clientEntries = !isServer

next.js v12.0.4 (correctly work):

clientEntries: {
  'main.js': [],
  'react-refresh': 'C:\\test-next\\.yarn\\__virtual__\\@next-react-refresh-utils-virtual-17b7e6438c\\0\\cache\\@next-react-refresh-utils-npm-12.0.4-d8661f51f6-7c1c9c3284.zip\\node_modules\\@next\\react-refresh-utils\\runtime.js',
  amp: './.yarn/__virtual__/next-virtual-f94b832183/0/cache/next-npm-12.0.4-fcbd6e5d3e-b9711e7d42.zip/node_modules/next/dist/client/dev/amp-dev',
  main: './.yarn/__virtual__/next-virtual-f94b832183/0/cache/next-npm-12.0.4-fcbd6e5d3e-b9711e7d42.zip/node_modules/next/dist/client/next-dev.js'
}

next.js v12.0.5-canary.11:

clientEntries: {
  'main.js': [],
  'react-refresh': 'C:\\test-next\\.yarn\\__virtual__\\@next-react-refresh-utils-virtual-a50cc4b923\\0\\cache\\@next-react-refresh-utils-npm-12.0.5-canary.11-d08910d2ba-2bab76619a.zip\\node_modules\\@next\\react-refresh-utils\\runtime.js',
  amp: './.yarn/__virtual__/next-virtual-1354126498/0/cache/next-npm-12.0.5-canary.11-e87fce5999-fdd462fb46.zip/node_modules/next/dist/client/dev/amp-dev',
  main: './.yarn/__virtual__/next-virtual-1354126498/0/cache/next-npm-12.0.5-canary.11-e87fce5999-fdd462fb46.zip/node_modules/next/dist/client/next-dev.js'
}

Both values are similar, so this issue shouldn't yarn side.

There is a way to debug, log and/or help?

FYI @sokra @timneutkens

@timruiterkamp
Copy link

@rtritto any update on this? I am running into the same issues right now

@rtritto
Copy link
Author

rtritto commented Nov 30, 2021

Nothing

@timruiterkamp
Copy link

@rtritto Hmm that's a shame.. I upgraded to yarn 3.1 and therefore had to upgrade Next to 12 but with i am running into the same issues as you do now.

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

@rtritto
Copy link
Author

rtritto commented Nov 30, 2021

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)

@timruiterkamp
Copy link

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 :)

@arcanis
Copy link
Contributor

arcanis commented Dec 1, 2021

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.

@arcanis
Copy link
Contributor

arcanis commented Dec 1, 2021

This sounds like the problematic commit: #31682

cc @sokra

@kachkaev
Copy link
Contributor

kachkaev commented Dec 2, 2021

A reproduction can be found here: kachkaev/njt#161

The main branch of that repo uses Yarn 3.1.1 with nodeLinker: node-modules and Next.js 12.0.5-canary.13. Everything works. The above PR switches the project to PnP, which breaks next dev and next build. I tried downgrading Next to 12.0.4 and it worked again.

Preview release works for the PR, but that’s because of a workaround on the Vercel side.

@rtritto
Copy link
Author

rtritto commented Dec 2, 2021

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

@rtritto
Copy link
Author

rtritto commented Dec 2, 2021

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

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

@rtritto rtritto closed this as completed Dec 2, 2021
@rtritto rtritto reopened this Dec 2, 2021
@rtritto
Copy link
Author

rtritto commented Dec 2, 2021

Maybe this issue should remain opened because of experimental (temporary) fix.

@kachkaev
Copy link
Contributor

kachkaev commented Dec 2, 2021

I no longer see any mentions of amp-dev.js after upgrading to Next.js v12.0.5-canary.14 and enabling swcFileReading: false. However, #31552 is still there.

@kachkaev
Copy link
Contributor

@rtritto could you try setting swcFileReading: false in next.config.js and upgrade to 12.0.8? The problem is probably resolved via #32867.

@rtritto
Copy link
Author

rtritto commented Jan 12, 2022

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.

@rtritto
Copy link
Author

rtritto commented Jan 13, 2022

This issue will be fixed with #33236

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Feb 14, 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.

5 participants