-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
With webpack 5 and once deployed, local files are not readable from APIs anymore #24700
Comments
Following @mmazzarolo suggestion in #8251, I can attest the problem actually comes with webpack 5. Disabling webpack 5 after updating fixes it: next.config.js module.exports = {
future: {
webpack5: false,
},
}; EDIT: module.exports = {
webpack5: false,
}; |
I manually opted into webpack5 and can confirm I'm also seeing this behaviour inside API routes ExampleAPI Route const CONTENT_DIR = path.join(process.cwd(), "src", "content");
export const getContentByDir = async (
dir: string,
options?: IGetContentOptions
) => {
const srcDir = path.join(CONTENT_DIR, dir);
if (!fs.lstatSync(srcDir)?.isDirectory()) {
// Error thrown to Vercel
throw Error(`${srcDir} is not a valid directory`);
}
// other unrelated code
}; Vercel Logs Error: ENOENT: no such file or directory, lstat '/var/task/src/content/blog'
at Object.lstatSync (fs.js:1077:3)
at getContentByDir (/var/task/.next/server/pages/api/sitemap.js:283:49)
at getBlogPaths (/var/task/.next/server/pages/api/sitemap.js:292:23)
at getAllPaths (/var/task/.next/server/pages/api/sitemap.js:313:67)
at getSitemapPaths (/var/task/.next/server/pages/api/sitemap.js:314:43)
at exports.modules.3692.__webpack_exports__.default (/var/task/.next/server/pages/api/sitemap.js:331:96)
at apiResolver (/var/task/node_modules/next/dist/next-server/server/api-utils.js:8:7)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Server.handleApiRequest (/var/task/node_modules/next/dist/next-server/server/next-server.js:66:462)
at async Object.fn (/var/task/node_modules/next/dist/next-server/server/next-server.js:58:580) {
errno: -2,
syscall: 'lstat',
code: 'ENOENT',
path: '/var/task/src/content/blog'
} Additional ContextI tried adding this to my webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.fallback.fs = false;
}
return config;
}, This behaviour doesn't occur when I opt-out of |
Hi, can someone who's run into this provide a repo with a minimal reproduction, we aren't able to reproduce this with the above provided information |
Hi @ijjk, thank you for looking into this. |
Good tip @QuentinRoy I can confirm that the addition of a second read appears to reveal the issue. edit: updated the deployment url |
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 |
@wworrall your tone is super unproductive and contributes nothing to this issue |
@jacksonhardaker, does your deployment matches the code in your repo? The deployed app appears functional. |
@QuentinRoy Thanks for the ping, I must have pasted the incorrect url. Updated. |
We have a slightly similar case. We can read files but only if one API endpoint is doing the Thanks for taking a look and providing help, Vercel crew. 🙏 EDIT: just realized it's the same issue as @QuentinRoy described above. Good to know we are not the only ones! |
Any update on this? |
@carl0s did you try the |
I will totally try that! |
I tried that with the mentioned version of Next.js, v11.1.3-canary.45.
I removed some reference to local paths, as they might be confusing. |
@carl0s This is a "known" issue... read about it here: i18next/next-i18next#1202 (comment) and here: i18next/next-i18next#1384 |
The update to 11.3 with
Seems similar to this ticket: emotion-js/emotion#850 and this old SO question (https://stackoverflow.com/questions/62526318/nextjs-emotionjs-and-vercel-error-err-require-esm-must-use-import-to-load-es). Installing Only one route of my app is affected I don't really get why specifically, probably because it's an MDX file, with I can reproduce only on Vercel so far, not locally. I can share a non-minimal repro if needed, this affect an open source project. |
@eric-burel the |
|
@ijjk First try after this update canary.86 gives me Then after a second try, it seems to partially fix the issue: I don't have trouble with API routes anymore. But my MDX page still doesn't work. 2021-10-20T15:24:05.039Z 2f2bc57a-9453-45f1-8b7c-785d883c2e14 ERROR TypeError: Cannot destructure property 'components' of 'object null' as it is null.
at Server.renderToResponseWithComponents (/var/task/node_modules/next/dist/server/next-server.js:985:90)
at Server.renderErrorToResponse (/var/task/node_modules/next/dist/server/next-server.js:1428:35)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Server.pipe (/var/task/node_modules/next/dist/server/next-server.js:866:25)
at async Object.fn (/var/task/node_modules/next/dist/server/next-server.js:671:21)
at async Router.execute (/var/task/node_modules/next/dist/server/router.js:205:32)
at async Server.run (/var/task/node_modules/next/dist/server/next-server.js:843:29)
at async Server.handleRequest (/var/task/node_modules/next/dist/server/next-server.js:293:20)
at async Server.<anonymous> (/var/task/___next_launcher.js:32:9) This page works locally but still not in Vercel. You can get the code here: https://github.com/eric-burel/vulcan-next/tree/main |
@eric-burel it looks like your issue is related to |
@ijjk I still get: steps to reproduce:
|
@adrai that appears to be an issue with running the package from the monorepo, the {
"name": "v10",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "canary",
"next-i18next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"prop-types": "^15.7.2"
}
} and the modules should be installed specific to the example along with running |
@ijjk you're right |
Much thanks for the help @ijjk I've made some progress. I ended up with the config described there in the relevant next-i18next ticket i18next/next-i18next#661 (comment) However, I have a new issue :/
The package is correctly listed in the dependencies. Sorry I'd like to help more but I don't fully understand what happens, and the error message is kinda vague here. That's maybe a different issue. Could there be some server-rendering happening? This is an MDX page using the row |
@eric-burel you are adding |
For anyone else who ran into the initial issue, please try upgrading to |
@ijjk Nope it doesn't actually work, if you reload the page again, you'll get a 500 error. After updating to canary 104 I still get the server error Thanks for the tip though, I think getting rid of |
I'm going to close this as this should be working properly in the latest version of Next.js |
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. |
What 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:
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/.The text was updated successfully, but these errors were encountered: