With webpack 5 and once deployed, local files are not readable from APIs anymore
See original GitHub issueWhat version of Next.js are you using?
10.2.0
What version of Node.js are you using?
14.0.0
What browser are you using?
Chrome,Firefox,Safari
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
Since updating to 10.2.0, local files are not accessible from apis anymore once deployed on Vercel. I do not know if it was on purpose, but it used to work fine before upgrading.
In both case, an internal server error is returned. After closer inspection of the logs, the error message is as follows:
[Error: ENOENT: no such file or directory, open '/app/data/metadata.yml'] {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/app/data/metadata.yml'
}
It went back to normal after downgrading to next 10.1.3.
EDIT: It seems the problem comes from webpack 5, it is working fine if webpack5 is disabled in next.config.js
.
EDIT: It does not fail if there is only one API trying to read only one local file. It is possible the problem occurs when multiple files have to be available for reading.
EDIT: According to @jacksonhardaker, this also fails when reading files from getServerSideProps
.
Expected Behavior
Local files should be readable from apis. If these are not embedded by default anymore, maybe an option could be used to indicate what files should be available?
To Reproduce
Here is an example showing APIs failing: https://github.com/QuentinRoy/vercel-local-min-example deployed at https://vercel-local-min-example.vercel.app.
Here is another example from @jacksonhardaker showing getServerSideProps
failing: https://github.com/jacksonhardaker/next-webpack-5-fs-bug deployed at https://next-webpack-5-fs-bug-jwegk8q1o-jacksonhardaker1.vercel.app/.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:28
- Comments:35 (22 by maintainers)
@wworrall your tone is super unproductive and contributes nothing to this issue
This is a major issue causing Vercel deployments to break silently (build completing successfully). Rolling back to webpack 4 for now - please fix asap, Vercel 😍. Also, perhaps add something to your tests as to which projects are automatically compatible with webpack5 https://nextjs.org/docs/messages/webpack5