-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Can't Build Next v9 With Non-React Components #8617
Comments
This is not a bug and expected behavior. In Next.js 8 it would actually build and expose The main constraint of Next.js is that pages are pages. |
Hello @timneutkens ; so there's no workaround to this? ie: Next not exposing these files? |
@zxiest this has been discussed many times in different GitHub issues. You shouldn't put components into pages as it:
Most recent discussion is here #4315 (comment) |
Thanks for the link. We shall restructure accordingly. |
Rethinking this, would it not be possible to add an This should not harm build speeds, not expose the files publicly (obviously this needs to be supported), and not harm code splitting. It's very annoying having to separate the files in many directories and looking for them every time you need to do an edit. I am a big fan of convention over configuration coming from the Rails world but have noticed it's much more efficient to keep component assets in the same directory. |
This has been discussed many times before as said and that still introduces security issues etc. You can keep pages only to expose routes though and then keep a separate directory with a structure that you want. |
Thank you for taking the time to respond =) This is what we have ended up doing. We're following this structure outside the /pages directory and using /pages for the aforementioned purpose only. |
But what to do with relay generated files placed under |
And yes relay-compiler allow to use one folder for this files, but we have hundreds of such. Not easy to import, find etc. So using |
For now I excluded webpack: (config /* : any */) => {
const originalEntry = config.entry;
config.entry = async () => {
const entries = await originalEntry();
const keys = Object.keys(entries);
keys.forEach(key => {
if (key.includes('/__generated__/')) {
delete entries[key];
}
});
return entries;
};
return config;
},
}) So can be used as a solution |
try to run relay on build step add graphql-cli dependency make some changes to fix NextJS error (vercel/next.js#8617) prevent default on link trigger error on server trigger error on server trigger error on server trigger error on server trigger error on server trigger error on server
Just an idea for disappointed folks, that came previously from create-react-app (like me). And would like to have a directory per page: Put your pages code inside src/pages
And reference
IMHO, you also get more control, and its easier to reason about what will be available in prod, since the pages/ directory stays really lean and simple. |
Any reason this is allowed in development mode? |
This does not make sense to be allowed in the development environment since it applies to the production environment. |
@istarkov's hack stopped working |
@TrySound it likely has a slash too many |
@timneutkens This is how the key look like |
Really went down the rabbit hole with this one. Got my page written, tests written and passing, and everything built fine in dev ( I first tried to add a custom Webpack config. After adding This has almost caused me to bail out on using Next.js for now. It's obvious that many folks would like to co-locate files next to pages for better developer experience. It's similar to the greatly improved developer experience of co-locating CSS files alongside their React components, instead of in some far-away directory (or back in the old days, one massive mysterious file). From reading other threads and this one, it seems that Next.js maintainers may be open to adding some sort of ignore or include/exclude to Other than this issue, everything else in Next.js has worked out pretty nicely, and it's really lovely. Thank you! @hiukky That solution seems somewhat reasonable, I'll give it a try. Thanks! |
This comment has been minimized.
This comment has been minimized.
NextJS won't let us build unless _every page is a page_. Meaning that we can't have styles.js files around. This is a workaround, explained here: vercel/next.js#8617 (comment)
https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions seems like a good way to tackle this for now. It requires you to rename all your pages to pageExtensions: ['page.tsx', 'page.ts', 'page.jsx', 'page.js'], Looks like #8454 (comment) discovered this first. |
…omponents (#22740) Feel free to edit this/suggest changes as you see fit to match the style of your docs or how you want this feature represented. There seemed to be many issues regarding colocating non-page files with page components in the `pages` directory where `pageExtensions` was finally suggested as a solution. I think it would be great to document it better since it seems to be a often requested workflow to colocate test, generated files, styles, and other files needed by page components in the `pages` directory. The note that exists in the docs currently alludes to the ability to do this but it doesn't contain much context that would help make it more discoverable. Relevant issues: #11113 (reply in thread) #8454 (comment) #8617 (comment) #3728 (comment)
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. |
Bug report
Describe the bug
After upgrading from v8.9 to v9, Next will refuse to build my project because of the presence of non-react components. There doesn't seem to be a setting I can add in next's config to get around this, forcing me to completely destructure my pages. Isn't there a way to disabled automatic static optimization?
Spectrum question here.
Error:
proceeded by the list of all the files that aren't react components (AKA the style and test files).
To Reproduce
I have setup a file structure as such:
Simply run
next build
oryarn build
Expected behavior
To build normally, like in Next v8.
The text was updated successfully, but these errors were encountered: