-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Code elimination broken for module that exports frontend and Node.js #16153
Comments
As of right now it's not possible to have both client-side JS and Node.js-specific code as the tree shaking of The elimination is only applied to page files in the |
Btw in this case, we're not even having frontend code, but just an import of a json object, that is unused. Maybe fixing this case could already be a good first step. |
Is it possible to test the scenario I described here in https://next-code-elimination.now.sh/ ? |
I've also been experiencing that using Prisma. I'm exposing a basic REST API from my Next.js backend, and I want to just use my Prisma model types for static type checking. |
I've tested that under a slightly different setup, using SQLite as a sort of extreme case (to avoid backend calls for data that is potentially configurable, like in a CMS - updates are done through git push -, but runtime access in readonly mode and without having to maintain it on a central server). In some settings it works, in others it doesn't. Here's an example of stack trace when it doesn't work: error - ./node_modules/@prisma/client/runtime/index.js:87:2855 so it fails on the instruction {AsyncResource:Iy}=required("async_hook") Note : I retried this morning, and the example works. So I'm not sure what happened. If I can reproduce, I'll publish a code example. |
A simple scenario that triggers this bug is moving the contents of a // Before
// pages/index.tsx:
import fs from 'fs';
export default function Home(){ return <div />; }
export async function getServerSideProps(){ /* some work using fs */ }
// After
// pages/index.tsx:
export { default as default, getServerSideProps } from '../helper.tsx';
// helper.tsx:
import fs from 'fs';
export default function Home(){ return <div />; }
export async function getServerSideProps(){ /* some work using fs */ } |
@denis-sokolov Did you find a workaround? |
I stopped exporting frontend and Node.js code from the same file. ¯\_(ツ)_/¯ |
Not sure I understand. In the example you gave above, were are you exporting frontend and Node.js code from the same file? I am trying to do the same, move code from the
|
I put front-end code and node.js code into separate files: export { HomePage as default } from 'views/Home';
export { getServerSideProps } from 'views/Home/server'; |
So there is no way currently to leave the getServerSideProps in the same file as the page code if I want to put them into a directory that is not |
Is this still not fixed (i.e. eliminating code in files outside the |
For App Router we've kept this issue in mind and changed the approach to no longer magically shake like with |
This closed issue has been automatically locked because it had no new activity for a month. 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
The code elimination is broken, if you import from a file, which exports both frontend and Node.js code.
To Reproduce
Clone and run:
https://github.com/timsuchanek/build-cv-messing-around
Expected behavior
The code elimination should sort out the frontend and Node.js code correctly.
Screenshots
System information
Additional context
This is an isolated reproduction of a problem a Prisma user hit with running Prisma Client in
getStaticProps
prisma/prisma#3252The text was updated successfully, but these errors were encountered: