Meteor-React-ssr - Asks for 'templating' package when i have 'static-html' Installed

184 views Asked by At

I am trying to implement meteor-react server-side rendering. I have removed the templating package and added static-html package as is the case when using react for ui in meteor.

The issue now is that when I run the app with any server side rendering implementation, it works fine. Meaning if I view page source, I see my bare-bone markup with my render target div. but when I implement the server rendering code, it gives this error

```

Error: Cannot find package "templating". Try "meteor add templating".
at makeInstallerOptions.fallback (packages/modules-runtime.js:597:13)
at Module.require (packages/modules-runtime.js:230:14)
at require (packages/modules-runtime.js:244:21)
at AccountsUIWrapper.js (imports/ui/AccountsUIWrapper.js:1:250)
at fileEvaluate (packages/modules-runtime.js:322:7)
at Module.require (packages/modules-runtime.js:224:14)
at require (packages/modules-runtime.js:244:21)
at App.js (imports/ui/App.js:1:386)
at fileEvaluate (packages/modules-runtime.js:322:7)
at Module.require (packages/modules-runtime.js:224:14)
at require (packages/modules-runtime.js:244:21)
at routes.js (imports/startup/routes.js:1:87)
at fileEvaluate (packages/modules-runtime.js:322:7)
at Module.require (packages/modules-runtime.js:224:14)
at require (packages/modules-runtime.js:244:21)
at main.js (server/main.js:1:558)
at fileEvaluate (packages/modules-runtime.js:322:7)
at Module.require (packages/modules-runtime.js:224:14)
at require (packages/modules-runtime.js:244:21)
at /Users/kenshinman/Desktop/projects/simple-todos/.meteor/local/build/programs/server/app/app.js:463:15
at /Users/kenshinman/Desktop/projects/simple-todos/.meteor/local/build/programs/server/boot.js:411:36
at Array.forEach (<anonymous>)

=> Exited with code: 1 => Your application is crashing. Waiting for file change.

```

Here is my server/main.js code

import { Tasks } from "../imports/api/tasks";
import React from "react";
import { Meteor } from "meteor/meteor";
import { onPageLoad } from "meteor/server-render";
import { StaticRouter, Switch } from "react-router-dom";
import { renderToString } from "react-dom/server";
import Routes from "../imports/startup/routes";

const siteName = "Todos";
const defaultImage = "https://loremflickr.com/320/240/baby";
const defaultMetaTags = `
<title>${siteName}</title>
<meta property="og:title"       content="${siteName}" />
<meta property="og:description" content="All your todos synced wherever you happen to be" />
<meta property="og:image"       content="${defaultImage}" />
`;

function createMetaTag(property, content) {
  return `<meta property="${property}" content="${content}">`;
}

onPageLoad(sink => {
  const { pathname } = sink.request.url;
  const meteorHost = Meteor.absoluteUrl();

  const App = props => {
    console.log(props);
    return (
      <StaticRouter location={props.location} context={{}}>
        <Switch>
          <Routes />
        </Switch>
      </StaticRouter>
    );
  };

  const content = renderToString(<App location={sink.request.url} />);

  sink.renderIntoElementById("render-target", content);

  const taskId = "asdlkjhfsda";
  const task = taskId ? Tasks.findOne({ _id: "listId" }) : null;
  // task count

  if (task) {
    const title = "task.text";
    const description = `This list contains 8 incomplete tasks`;
    const fullUrl = meteorHost + pathname.replace(/^\/+/g, "");
    sink.appendToHead(createMetaTag("og:title", title));
    sink.appendToHead(createMetaTag("og:description", description));
    sink.appendToHead(createMetaTag("og:url", fullUrl));
    sink.appendToHead(createMetaTag("og:image", defaultImage));
    sink.appendToHead(createMetaTag("og:site_name", siteName));
  } else {
    sink.appendToHead(defaultMetaTags);
    sink.appendToHead(createMetaTag("og:url", meteorHost));
  }
});

But when I comment the line import Routes from "../imports/startup/routes"; and all appearances of route, everything works fine again.

Here is the route file code

import React from "react";
import App from "../ui/App";

import { Switch, Route } from "react-router-dom";

const Routes = () => (
 <div>
   <Route exact path="/" component={App} />
  <Route exact path="/test" render={() => <h2>This is the test page</h2>} />
 </div>
);

export default Routes;

How can I make this work and stop getting this error?

Thanks.

1

There are 1 answers

1
Kenshinman On

Solved. Forgot I imported Template from meteor/templating in my accounts ui config template. It's working now.