Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Error parsing triggers while deploying cloud functions - Firebase

I'm using renderToString function from react-dom (on my server side). The code looks like (+/-):

import Home from './app/containers/Home';
const app = express();

app.get('**', (req, res) => {
  const html = renderToString(<Home />);
  res.set('Cache-Control', 'public, max-age=600, s-maxage=1200');
  res.send(html);
});

Everything goes smooth, until I try to deploy it on the server.

Example error in the console:

Error: Error parsing triggers: Cannot find module 'store/Home/actions'

When it appears?

If I change my path to some other component, which does not use any other components (only modules from node, like react or react-redux) it works correctly.

But if I try to use some component which uses other components and imports them, e.g.:

var _CreateUser = require('components/Pages/CreateUser'); (it's in the rendered component)

Now it will fail with error:

Error: Error parsing triggers: Cannot find module 'components/Pages/CreateUser'

So currently Im stuck, because I have to use my whole app on server side, not just a single component which doesn't import anything :)

Why does it work this way? Why does it fail? Is it bad webpack config fail?

Looking forward for any help. Thank you.

Note, as I said above, if I render to string some component with any imports (that doesn't use any other component in it) - the server side rendering works fine and Im able to see the renderedToString content before page loads.

enter image description here

like image 334
Patrickkx Avatar asked Apr 13 '26 14:04

Patrickkx


1 Answers

Everywhere you import local modules you need to include the directory in the path otherwise it will search node_modules for a named package and ultimately fail.

require('./store/Home/actions');

Or:

import HomeActions from './store/Home/actions';

...depending on which import style you're using. An accurate directory is always needed as a part of the import/require statement.

like image 194
deezy Avatar answered Apr 15 '26 02:04

deezy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!