question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot set property of 'template' of undefined

See original GitHub issue

I get this Error:

-  Building for production... **ERROR  TypeError: Cannot set property 'template' of undefined
TypeError: Cannot set property 'template' of undefined**
    at config.plugin.tap.args (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\vue-cli-plugin-prerender-spa\index.js:55:26)
    at Object.tap (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\webpack-chain\src\Plugin.js:24:24)
    at config (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\vue-cli-plugin-prerender-spa\index.js:54:29)
    at webpackChainFns.forEach.fn (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\@vue\cli-service\lib\Service.js:227:40)
    at Array.forEach (<anonymous>)
    at Service.resolveChainableWebpackConfig (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\@vue\cli-service\lib\Service.js:227:26)
    at PluginAPI.resolveChainableWebpackConfig (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\@vue\cli-service\lib\PluginAPI.js:128:25)
    at module.exports (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\@vue\cli-service\lib\commands\build\resolveAppConfig.js:2:22)
    at build (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\@vue\cli-service\lib\commands\build\index.js:138:50)
    at api.registerCommand (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\@vue\cli-service\lib\commands\build\index.js:85:13)
    at Service.run (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\@vue\cli-service\lib\Service.js:221:12)
    at Object.<anonymous> (C:\Users\erikr\source\repos\ToDoStudio\To-Do.Studio Info\TDS.Web\node_modules\@vue\cli-service\bin\vue-cli-service.js:36:9)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! to-do.studio.info@0.1.0 build: `vue-cli-service build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the to-do.studio.info@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

I am using a normal vue-cli based project using multiple pages (and no main.js)

pages: {
    "index": {
      entry: "src/home.js",
      template: "public/home.html",
      filename: "index.html",
    },
    "home-french": {
      entry: "src/homeFrench.js",
      template: "public/home-french.html",
      filename: "home-french.html",
    },
    "privacy-policy": {
      entry: "src/privacyPolicy.js",
      template: "public/privacy-policy.html",
      filename: "privacy-policy.html",
    },
    "terms-of-use": {
      entry: "src/termsOfUse.js",
      template: "public/terms-of-use.html",
      filename: "terms-of-use.html",
    },
  },

  pluginOptions: {
    prerenderSpa: {
      registry: undefined,
      renderRoutes: [
        '/',
        '/home-french',
        '/terms-of-use',
        '/privacy-policy'
      ],
      useRenderEvent: true,
      headless: true,
      onlyProduction: true
    }

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
mmusketcommented, Mar 12, 2019

In multi page mode vue creates different objects for every ‘page’

I noticed I have

'html-index' => [Object],
'html-app' => [Object],

rather than just html

changing the line

config.plugin("html").tap(args => {

to

config.plugin("html-index").tap(args => {

allows to the plugin to keep working, although I am unsure at what side effect problems it creates. I suspect that if you want to prerender view from different pages the plugin will not work at this stage.

1reaction
wvfflecommented, Aug 20, 2019

I’ve occured same error when using pug template. I have /src/index.pug file and no /src/public/index.html file.

My config is as so:

  pages: {
    index: {
      entry: './src/main.js',
      template: './src/index.pug'
    }
  }

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'template' of undefined ...
I forgot to define the header cell for the actions. So it was throwing that error. Here is the code which solved this...
Read more >
Error using templates: "Cannot read property ... - Syncfusion
Error message in the browser console: ERROR TypeError: Cannot read property 'template' of undefined at eval (template.js:44)
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Why is the error "Cannot read properties of undefined (reading ...
The problem turned out to be with targeting this.template.host.style . I stopped doing this and instead used the querySelector() method ...
Read more >
typeerror: cannot set properties of undefined created() vue
You are seeing this error because you are initializing "board" to an empty array. The component tries to evaluate "board.category.title" when it binds...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found