Next.js Discord

Discord Forum

Is there a way to give code splitting hints when using Server Components? (app directory)

Unanswered
Netherland Dwarf posted this in #help-forum
Open in Discord
Netherland DwarfOP
I am getting this error message when trying to use yahoo-finance2 in my server component. It works correctly when using it with getStaticProps() in the "pages" directory so I don't think it's an issue with the module itself.

I think for some reason next.js sees my import of the yahoo-finance2 module and thinks it needs to be included in the client side, and I'm getting an error since the module only works within node.js

(code inside of src/app/page.tsx)

import yahooFinance from 'yahoo-finance2';
export default async function Home() {
      
const results = await yahooFinance.quote('AAPL');
      return (
          ...
      );
}

 error ./node_modules/.pnpm/yahoo-finance2@2.4.1/node_modules/yahoo-finance2/dist/esm/src/lib/fetchDevel.js:6:17
Module not found: Can't resolve '../../tests/http/'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/.pnpm/yahoo-finance2@2.4.1/node_modules/yahoo-finance2/dist/esm/src/env-node.js
./node_modules/.pnpm/yahoo-finance2@2.4.1/node_modules/yahoo-finance2/dist/esm/src/index-node.js

1 Reply