Skip to content
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

How to execute getInitialProps in node only #93

Closed
cdock1029 opened this issue Aug 12, 2018 · 2 comments
Closed

How to execute getInitialProps in node only #93

cdock1029 opened this issue Aug 12, 2018 · 2 comments

Comments

@cdock1029
Copy link

Or.. How do we only fetch data in a node context / use node-only data fetching dependencies?

Since use-case is static builds, I want to fetch data only during build.
In fact, I'm trying to build a bundle-less site, so my expectation is client-side context should never come into play with this static function.

Using firebase-admin, it shows errors related to missing node libraries.

Tried to copy something similar from a next.js discussion vercel/next.js#219 (comment)
not surprisingly it didn't work.

Thanks for this library by the way!

@jxnblk
Copy link
Member

jxnblk commented Aug 14, 2018

If you use the --static flag, it will output HTML without the JS bundle and getInitialProps should work as expected

@cdock1029
Copy link
Author

I was having issues with getting firebase-admin (a node-only package) to build, even using --static flag.

My solution was from this stack-overflow answer:

In webpack.config.js add the following:

const nodeExternals = require('webpack-node-externals')
module.exports = {
  target: 'node', // in order to ignore built-in modules like path, fs, etc.
  externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants