nuxt-community / express-template

Starter template for Nuxt 2 with Express.
https://codesandbox.io/s/github/nuxt-community/express-template
1.25k stars 239 forks source link

You may need an appropriate loader to handle this file type. (Extending Nuxt.js router config) #109

Closed jmcmullen closed 6 years ago

jmcmullen commented 6 years ago

When I extend the router through my nuxt.config.js like this:


const router = require(`./routes/${currentRegion}`);

module.exports = {
   router: {
    ...router,
    scrollBehavior() {
      return { x: 0, y: 0 };
    },
  },

  ...
}

I get the following error:

 warning  in ./routes/nz/faq.vue

Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <template>
|   <section>
|     <header>

 @ ./routes ^\.\/.*$
 @ ./nuxt.config.js
 @ ./server/index.js
This question is available on Nuxt.js community (#c89)
posva commented 6 years ago

it shouldn't happen since it's just a vue file. but if you are extracting router options from a dynamic path make it as specific as possible so webpack can figure out exactly the files you are looking after, otherwise, it will try every possible path. One simple solution is putting those files in specific folders. Adding the .js extension at the end of the required path should also work

jmcmullen commented 6 years ago

Cheers!

Changing it to const router = require(`./routes/${currentRegion}/index.js`); fixed the problem.