Run nuxt on https locally – problem with nuxt.config.js












0















I am trying to run nuxt locally with https to test some geolocation stuff.
(https://nuxtjs.org/, https://nuxtjs.org/api/nuxt)



I was following this tutorial:
https://www.mattshull.com/blog/https-on-localhost



And then I found this:
https://github.com/nuxt/nuxt.js/issues/146



Both links seem to describe pretty nicely how to run nuxt with server.js programmatically.



The thing is that in my nuxt.config.js I seem to have some problems.
I get the following error when runnung yarn dev:



/Users/USER/Documents/github/mynuxtrepo/nuxt.config.js:2
import { module } from 'npmmodule'

> SyntaxError: Unexpected token {


In my nuxt config I import a custom helper to generate localized routes. Not really important what it does but obviously it can't handle the import syntax.
I assume that the node version does not understand.



So how can I get it to run? Do I have to require everything instead of importing?
Or is my assumption wrong and the cause lies somewhere totally different?



Thank you for your help
Cheers.



------
Edit 1:

My nuxt config looks like this:



// eslint-disable-next-line prettier/prettier
import { generateLocalizedRoutes, generateRoutesFromData } from 'vuecid-helpers'
import config from './config'

// TODO: Add your post types
const postTypes = [{ type: 'pages' }, { type: 'posts', paginated: true }]

// TODO: Add your site title
const siteTitle = 'Title'
const shortTitle = 'short title'
const siteDescription = 'Page demonstrated with a wonderful example'
const themeColor = '#ffffff'
// TODO: Replace favicon source file in /static/icon.png (512px x 512px)
// eslint-disable-next-line prettier/prettier
const iconSizes = [32, 57, 60, 72, 76, 144, 120, 144, 152, 167, 180, 192, 512]

module.exports = {
mode: 'universal',
/*
** Headers of the page
*/
head: {
title: 'Loading…',
htmlAttrs: {
lang: config.env.DEFAULTLANG,
dir: 'ltr' // define directionality of text globally
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },

// TODO: Check this info
{ name: 'author', content: 'Author' },
{ name: 'theme-color', content: themeColor },

// TODO: Add or remove google-site-verification
{
name: 'google-site-verification',
content: '...W1GdU'
}
],
link:
},

/*
** env: lets you create environment variables that will be shared for the client and server-side.
*/
env: config.env,

/*
** Customize the progress-bar color
** TODO: Set your desired loading bar color
*/
loading: { color: '#0000ff' },

/*
** CSS
*/
css: ['@/assets/css/main.scss'],

/*
** Plugins
*/
plugins: [
{ src: '~/plugins/global.js' },
{ src: '~/plugins/throwNuxtError.js' },
{ src: '~/plugins/axios' },
{ src: '~/plugins/whatinput.js', ssr: false },
{ src: '~/plugins/i18n.js', injectAs: 'i18n' },
{ src: '~/plugins/vuex-router-sync' },
{ src: '~/plugins/vue-bows' },
{ src: '~/plugins/vue-breakpoint-component', ssr: false }
],

/*
** Modules
*/
modules: [
'@nuxtjs/axios',
'@nuxtjs/sitemap',
[
'@nuxtjs/pwa',
{
icon: {
sizes: iconSizes
},
// Override certain meta tags
meta: {
viewport: 'width=device-width, initial-scale=1',
favicon: true // Generates only apple-touch-icon
},
manifest: {
name: siteTitle,
lang: config.env.DEFAULTLANG,
dir: 'ltr',
short_name: shortTitle,
theme_color: themeColor,
start_url: '/',
display: 'standalone',
background_color: '#fff',
description: siteDescription
}
}
]
],

/*
** Workbox config
*/
workbox: {
config: {
debug: false,
cacheId: siteTitle
}
},

/*
** Axios config
*/
axios: {
baseURL: '/'
},

/*
** Generate
*/
generate: {
subFolders: true,
routes: [
...generateRoutesFromData({
langs: config.env.LANGS,
postTypes: postTypes,
dataPath: '../../../../../static/data',
bundle: 'basic',
homeSlug: config.env.HOMESLUG,
errorPrefix: config.env.ERROR_PREFIX
})
]
},

/*
** Build configuration
*/
build: {
extend(config, { isDev, isClient }) {
/*
** Run ESLINT on save
*/
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
},

/*
** Router
*/
router: {
linkActiveClass: 'is-active',
linkExactActiveClass: 'is-active-exact',
middleware: ['i18n'],
extendRoutes(routes) {
// extends basic routes (based on your files/folders in pages directory) with i18n locales (from our config.js)
const newRoutes = generateLocalizedRoutes({
baseRoutes: routes,
defaultLang: config.env.DEFAULTLANG,
langs: config.env.LANGS,
routesAliases: config.routesAliases
})

// Clear array
routes.splice(0, routes.length)

// Push newly created routes
routes.push(...newRoutes)
}
},

/*
** Sitemap Configuration
*/
sitemap: {
path: '/sitemap.xml',
hostname: config.env.FRONTENDURLPRODUCTION,
cacheTime: 1000 * 60 * 15,
generate: true,
routes: [
...generateRoutesFromData({
langs: config.env.LANGS,
postTypes: postTypes,
dataPath: '../../../../../static/data',
bundle: 'basic',
homeSlug: config.env.HOMESLUG,
errorPrefix: config.env.ERROR_PREFIX
})
]
}
}


You can see that the generateLocalizedRoutes and the generateRoutesFromData methods are used to generate localized routes and is also taking post json files to generate routes from data (:slug).



--------- Edit 2:
I got it to run eventually.
I had to require all parts within the nuxt.config.js instead of importing them. I also resolved issues with the certificates. So I thought it was all cool 🚀.



BUT!!! 🚧:
Then I found out that I had my config file used within my post template.
So I thought I would also require the file within my template:
Like const config = require('~/config').
But then I would get this error:




[nuxt] Error while initializing app TypeError: ""exports" is read-only"




After some research, I found that is probably a thing when using common.js require and module.exports together with ES6 import/export within my project. (Probably linked to: https://github.com/FranckFreiburger/vue-pdf/issues/1).



So how could I still use my config.js when running nuxt programmatically (with require) and then also within my app?



I am glad to hear any ideas on this...
Cheers










share|improve this question

























  • Show the whole nuxt.config.js

    – Styx
    Jan 19 at 20:03











  • What nuxt version?

    – Aldarund
    Jan 19 at 20:59











  • @Aldarund Newest nuxt version: 2.3.4

    – Merc
    Jan 19 at 23:16











  • @Styx I edited my question and added my nuxt config

    – Merc
    Jan 19 at 23:16











  • I also tried to add dev: (process.env.NODE_ENV !== 'production') to my nuxt.config.js as indicated here, but no success: nuxtjs.org/api/configuration-dev#the-dev-property

    – Merc
    Jan 19 at 23:24
















0















I am trying to run nuxt locally with https to test some geolocation stuff.
(https://nuxtjs.org/, https://nuxtjs.org/api/nuxt)



I was following this tutorial:
https://www.mattshull.com/blog/https-on-localhost



And then I found this:
https://github.com/nuxt/nuxt.js/issues/146



Both links seem to describe pretty nicely how to run nuxt with server.js programmatically.



The thing is that in my nuxt.config.js I seem to have some problems.
I get the following error when runnung yarn dev:



/Users/USER/Documents/github/mynuxtrepo/nuxt.config.js:2
import { module } from 'npmmodule'

> SyntaxError: Unexpected token {


In my nuxt config I import a custom helper to generate localized routes. Not really important what it does but obviously it can't handle the import syntax.
I assume that the node version does not understand.



So how can I get it to run? Do I have to require everything instead of importing?
Or is my assumption wrong and the cause lies somewhere totally different?



Thank you for your help
Cheers.



------
Edit 1:

My nuxt config looks like this:



// eslint-disable-next-line prettier/prettier
import { generateLocalizedRoutes, generateRoutesFromData } from 'vuecid-helpers'
import config from './config'

// TODO: Add your post types
const postTypes = [{ type: 'pages' }, { type: 'posts', paginated: true }]

// TODO: Add your site title
const siteTitle = 'Title'
const shortTitle = 'short title'
const siteDescription = 'Page demonstrated with a wonderful example'
const themeColor = '#ffffff'
// TODO: Replace favicon source file in /static/icon.png (512px x 512px)
// eslint-disable-next-line prettier/prettier
const iconSizes = [32, 57, 60, 72, 76, 144, 120, 144, 152, 167, 180, 192, 512]

module.exports = {
mode: 'universal',
/*
** Headers of the page
*/
head: {
title: 'Loading…',
htmlAttrs: {
lang: config.env.DEFAULTLANG,
dir: 'ltr' // define directionality of text globally
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },

// TODO: Check this info
{ name: 'author', content: 'Author' },
{ name: 'theme-color', content: themeColor },

// TODO: Add or remove google-site-verification
{
name: 'google-site-verification',
content: '...W1GdU'
}
],
link:
},

/*
** env: lets you create environment variables that will be shared for the client and server-side.
*/
env: config.env,

/*
** Customize the progress-bar color
** TODO: Set your desired loading bar color
*/
loading: { color: '#0000ff' },

/*
** CSS
*/
css: ['@/assets/css/main.scss'],

/*
** Plugins
*/
plugins: [
{ src: '~/plugins/global.js' },
{ src: '~/plugins/throwNuxtError.js' },
{ src: '~/plugins/axios' },
{ src: '~/plugins/whatinput.js', ssr: false },
{ src: '~/plugins/i18n.js', injectAs: 'i18n' },
{ src: '~/plugins/vuex-router-sync' },
{ src: '~/plugins/vue-bows' },
{ src: '~/plugins/vue-breakpoint-component', ssr: false }
],

/*
** Modules
*/
modules: [
'@nuxtjs/axios',
'@nuxtjs/sitemap',
[
'@nuxtjs/pwa',
{
icon: {
sizes: iconSizes
},
// Override certain meta tags
meta: {
viewport: 'width=device-width, initial-scale=1',
favicon: true // Generates only apple-touch-icon
},
manifest: {
name: siteTitle,
lang: config.env.DEFAULTLANG,
dir: 'ltr',
short_name: shortTitle,
theme_color: themeColor,
start_url: '/',
display: 'standalone',
background_color: '#fff',
description: siteDescription
}
}
]
],

/*
** Workbox config
*/
workbox: {
config: {
debug: false,
cacheId: siteTitle
}
},

/*
** Axios config
*/
axios: {
baseURL: '/'
},

/*
** Generate
*/
generate: {
subFolders: true,
routes: [
...generateRoutesFromData({
langs: config.env.LANGS,
postTypes: postTypes,
dataPath: '../../../../../static/data',
bundle: 'basic',
homeSlug: config.env.HOMESLUG,
errorPrefix: config.env.ERROR_PREFIX
})
]
},

/*
** Build configuration
*/
build: {
extend(config, { isDev, isClient }) {
/*
** Run ESLINT on save
*/
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
},

/*
** Router
*/
router: {
linkActiveClass: 'is-active',
linkExactActiveClass: 'is-active-exact',
middleware: ['i18n'],
extendRoutes(routes) {
// extends basic routes (based on your files/folders in pages directory) with i18n locales (from our config.js)
const newRoutes = generateLocalizedRoutes({
baseRoutes: routes,
defaultLang: config.env.DEFAULTLANG,
langs: config.env.LANGS,
routesAliases: config.routesAliases
})

// Clear array
routes.splice(0, routes.length)

// Push newly created routes
routes.push(...newRoutes)
}
},

/*
** Sitemap Configuration
*/
sitemap: {
path: '/sitemap.xml',
hostname: config.env.FRONTENDURLPRODUCTION,
cacheTime: 1000 * 60 * 15,
generate: true,
routes: [
...generateRoutesFromData({
langs: config.env.LANGS,
postTypes: postTypes,
dataPath: '../../../../../static/data',
bundle: 'basic',
homeSlug: config.env.HOMESLUG,
errorPrefix: config.env.ERROR_PREFIX
})
]
}
}


You can see that the generateLocalizedRoutes and the generateRoutesFromData methods are used to generate localized routes and is also taking post json files to generate routes from data (:slug).



--------- Edit 2:
I got it to run eventually.
I had to require all parts within the nuxt.config.js instead of importing them. I also resolved issues with the certificates. So I thought it was all cool 🚀.



BUT!!! 🚧:
Then I found out that I had my config file used within my post template.
So I thought I would also require the file within my template:
Like const config = require('~/config').
But then I would get this error:




[nuxt] Error while initializing app TypeError: ""exports" is read-only"




After some research, I found that is probably a thing when using common.js require and module.exports together with ES6 import/export within my project. (Probably linked to: https://github.com/FranckFreiburger/vue-pdf/issues/1).



So how could I still use my config.js when running nuxt programmatically (with require) and then also within my app?



I am glad to hear any ideas on this...
Cheers










share|improve this question

























  • Show the whole nuxt.config.js

    – Styx
    Jan 19 at 20:03











  • What nuxt version?

    – Aldarund
    Jan 19 at 20:59











  • @Aldarund Newest nuxt version: 2.3.4

    – Merc
    Jan 19 at 23:16











  • @Styx I edited my question and added my nuxt config

    – Merc
    Jan 19 at 23:16











  • I also tried to add dev: (process.env.NODE_ENV !== 'production') to my nuxt.config.js as indicated here, but no success: nuxtjs.org/api/configuration-dev#the-dev-property

    – Merc
    Jan 19 at 23:24














0












0








0








I am trying to run nuxt locally with https to test some geolocation stuff.
(https://nuxtjs.org/, https://nuxtjs.org/api/nuxt)



I was following this tutorial:
https://www.mattshull.com/blog/https-on-localhost



And then I found this:
https://github.com/nuxt/nuxt.js/issues/146



Both links seem to describe pretty nicely how to run nuxt with server.js programmatically.



The thing is that in my nuxt.config.js I seem to have some problems.
I get the following error when runnung yarn dev:



/Users/USER/Documents/github/mynuxtrepo/nuxt.config.js:2
import { module } from 'npmmodule'

> SyntaxError: Unexpected token {


In my nuxt config I import a custom helper to generate localized routes. Not really important what it does but obviously it can't handle the import syntax.
I assume that the node version does not understand.



So how can I get it to run? Do I have to require everything instead of importing?
Or is my assumption wrong and the cause lies somewhere totally different?



Thank you for your help
Cheers.



------
Edit 1:

My nuxt config looks like this:



// eslint-disable-next-line prettier/prettier
import { generateLocalizedRoutes, generateRoutesFromData } from 'vuecid-helpers'
import config from './config'

// TODO: Add your post types
const postTypes = [{ type: 'pages' }, { type: 'posts', paginated: true }]

// TODO: Add your site title
const siteTitle = 'Title'
const shortTitle = 'short title'
const siteDescription = 'Page demonstrated with a wonderful example'
const themeColor = '#ffffff'
// TODO: Replace favicon source file in /static/icon.png (512px x 512px)
// eslint-disable-next-line prettier/prettier
const iconSizes = [32, 57, 60, 72, 76, 144, 120, 144, 152, 167, 180, 192, 512]

module.exports = {
mode: 'universal',
/*
** Headers of the page
*/
head: {
title: 'Loading…',
htmlAttrs: {
lang: config.env.DEFAULTLANG,
dir: 'ltr' // define directionality of text globally
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },

// TODO: Check this info
{ name: 'author', content: 'Author' },
{ name: 'theme-color', content: themeColor },

// TODO: Add or remove google-site-verification
{
name: 'google-site-verification',
content: '...W1GdU'
}
],
link:
},

/*
** env: lets you create environment variables that will be shared for the client and server-side.
*/
env: config.env,

/*
** Customize the progress-bar color
** TODO: Set your desired loading bar color
*/
loading: { color: '#0000ff' },

/*
** CSS
*/
css: ['@/assets/css/main.scss'],

/*
** Plugins
*/
plugins: [
{ src: '~/plugins/global.js' },
{ src: '~/plugins/throwNuxtError.js' },
{ src: '~/plugins/axios' },
{ src: '~/plugins/whatinput.js', ssr: false },
{ src: '~/plugins/i18n.js', injectAs: 'i18n' },
{ src: '~/plugins/vuex-router-sync' },
{ src: '~/plugins/vue-bows' },
{ src: '~/plugins/vue-breakpoint-component', ssr: false }
],

/*
** Modules
*/
modules: [
'@nuxtjs/axios',
'@nuxtjs/sitemap',
[
'@nuxtjs/pwa',
{
icon: {
sizes: iconSizes
},
// Override certain meta tags
meta: {
viewport: 'width=device-width, initial-scale=1',
favicon: true // Generates only apple-touch-icon
},
manifest: {
name: siteTitle,
lang: config.env.DEFAULTLANG,
dir: 'ltr',
short_name: shortTitle,
theme_color: themeColor,
start_url: '/',
display: 'standalone',
background_color: '#fff',
description: siteDescription
}
}
]
],

/*
** Workbox config
*/
workbox: {
config: {
debug: false,
cacheId: siteTitle
}
},

/*
** Axios config
*/
axios: {
baseURL: '/'
},

/*
** Generate
*/
generate: {
subFolders: true,
routes: [
...generateRoutesFromData({
langs: config.env.LANGS,
postTypes: postTypes,
dataPath: '../../../../../static/data',
bundle: 'basic',
homeSlug: config.env.HOMESLUG,
errorPrefix: config.env.ERROR_PREFIX
})
]
},

/*
** Build configuration
*/
build: {
extend(config, { isDev, isClient }) {
/*
** Run ESLINT on save
*/
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
},

/*
** Router
*/
router: {
linkActiveClass: 'is-active',
linkExactActiveClass: 'is-active-exact',
middleware: ['i18n'],
extendRoutes(routes) {
// extends basic routes (based on your files/folders in pages directory) with i18n locales (from our config.js)
const newRoutes = generateLocalizedRoutes({
baseRoutes: routes,
defaultLang: config.env.DEFAULTLANG,
langs: config.env.LANGS,
routesAliases: config.routesAliases
})

// Clear array
routes.splice(0, routes.length)

// Push newly created routes
routes.push(...newRoutes)
}
},

/*
** Sitemap Configuration
*/
sitemap: {
path: '/sitemap.xml',
hostname: config.env.FRONTENDURLPRODUCTION,
cacheTime: 1000 * 60 * 15,
generate: true,
routes: [
...generateRoutesFromData({
langs: config.env.LANGS,
postTypes: postTypes,
dataPath: '../../../../../static/data',
bundle: 'basic',
homeSlug: config.env.HOMESLUG,
errorPrefix: config.env.ERROR_PREFIX
})
]
}
}


You can see that the generateLocalizedRoutes and the generateRoutesFromData methods are used to generate localized routes and is also taking post json files to generate routes from data (:slug).



--------- Edit 2:
I got it to run eventually.
I had to require all parts within the nuxt.config.js instead of importing them. I also resolved issues with the certificates. So I thought it was all cool 🚀.



BUT!!! 🚧:
Then I found out that I had my config file used within my post template.
So I thought I would also require the file within my template:
Like const config = require('~/config').
But then I would get this error:




[nuxt] Error while initializing app TypeError: ""exports" is read-only"




After some research, I found that is probably a thing when using common.js require and module.exports together with ES6 import/export within my project. (Probably linked to: https://github.com/FranckFreiburger/vue-pdf/issues/1).



So how could I still use my config.js when running nuxt programmatically (with require) and then also within my app?



I am glad to hear any ideas on this...
Cheers










share|improve this question
















I am trying to run nuxt locally with https to test some geolocation stuff.
(https://nuxtjs.org/, https://nuxtjs.org/api/nuxt)



I was following this tutorial:
https://www.mattshull.com/blog/https-on-localhost



And then I found this:
https://github.com/nuxt/nuxt.js/issues/146



Both links seem to describe pretty nicely how to run nuxt with server.js programmatically.



The thing is that in my nuxt.config.js I seem to have some problems.
I get the following error when runnung yarn dev:



/Users/USER/Documents/github/mynuxtrepo/nuxt.config.js:2
import { module } from 'npmmodule'

> SyntaxError: Unexpected token {


In my nuxt config I import a custom helper to generate localized routes. Not really important what it does but obviously it can't handle the import syntax.
I assume that the node version does not understand.



So how can I get it to run? Do I have to require everything instead of importing?
Or is my assumption wrong and the cause lies somewhere totally different?



Thank you for your help
Cheers.



------
Edit 1:

My nuxt config looks like this:



// eslint-disable-next-line prettier/prettier
import { generateLocalizedRoutes, generateRoutesFromData } from 'vuecid-helpers'
import config from './config'

// TODO: Add your post types
const postTypes = [{ type: 'pages' }, { type: 'posts', paginated: true }]

// TODO: Add your site title
const siteTitle = 'Title'
const shortTitle = 'short title'
const siteDescription = 'Page demonstrated with a wonderful example'
const themeColor = '#ffffff'
// TODO: Replace favicon source file in /static/icon.png (512px x 512px)
// eslint-disable-next-line prettier/prettier
const iconSizes = [32, 57, 60, 72, 76, 144, 120, 144, 152, 167, 180, 192, 512]

module.exports = {
mode: 'universal',
/*
** Headers of the page
*/
head: {
title: 'Loading…',
htmlAttrs: {
lang: config.env.DEFAULTLANG,
dir: 'ltr' // define directionality of text globally
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },

// TODO: Check this info
{ name: 'author', content: 'Author' },
{ name: 'theme-color', content: themeColor },

// TODO: Add or remove google-site-verification
{
name: 'google-site-verification',
content: '...W1GdU'
}
],
link:
},

/*
** env: lets you create environment variables that will be shared for the client and server-side.
*/
env: config.env,

/*
** Customize the progress-bar color
** TODO: Set your desired loading bar color
*/
loading: { color: '#0000ff' },

/*
** CSS
*/
css: ['@/assets/css/main.scss'],

/*
** Plugins
*/
plugins: [
{ src: '~/plugins/global.js' },
{ src: '~/plugins/throwNuxtError.js' },
{ src: '~/plugins/axios' },
{ src: '~/plugins/whatinput.js', ssr: false },
{ src: '~/plugins/i18n.js', injectAs: 'i18n' },
{ src: '~/plugins/vuex-router-sync' },
{ src: '~/plugins/vue-bows' },
{ src: '~/plugins/vue-breakpoint-component', ssr: false }
],

/*
** Modules
*/
modules: [
'@nuxtjs/axios',
'@nuxtjs/sitemap',
[
'@nuxtjs/pwa',
{
icon: {
sizes: iconSizes
},
// Override certain meta tags
meta: {
viewport: 'width=device-width, initial-scale=1',
favicon: true // Generates only apple-touch-icon
},
manifest: {
name: siteTitle,
lang: config.env.DEFAULTLANG,
dir: 'ltr',
short_name: shortTitle,
theme_color: themeColor,
start_url: '/',
display: 'standalone',
background_color: '#fff',
description: siteDescription
}
}
]
],

/*
** Workbox config
*/
workbox: {
config: {
debug: false,
cacheId: siteTitle
}
},

/*
** Axios config
*/
axios: {
baseURL: '/'
},

/*
** Generate
*/
generate: {
subFolders: true,
routes: [
...generateRoutesFromData({
langs: config.env.LANGS,
postTypes: postTypes,
dataPath: '../../../../../static/data',
bundle: 'basic',
homeSlug: config.env.HOMESLUG,
errorPrefix: config.env.ERROR_PREFIX
})
]
},

/*
** Build configuration
*/
build: {
extend(config, { isDev, isClient }) {
/*
** Run ESLINT on save
*/
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
},

/*
** Router
*/
router: {
linkActiveClass: 'is-active',
linkExactActiveClass: 'is-active-exact',
middleware: ['i18n'],
extendRoutes(routes) {
// extends basic routes (based on your files/folders in pages directory) with i18n locales (from our config.js)
const newRoutes = generateLocalizedRoutes({
baseRoutes: routes,
defaultLang: config.env.DEFAULTLANG,
langs: config.env.LANGS,
routesAliases: config.routesAliases
})

// Clear array
routes.splice(0, routes.length)

// Push newly created routes
routes.push(...newRoutes)
}
},

/*
** Sitemap Configuration
*/
sitemap: {
path: '/sitemap.xml',
hostname: config.env.FRONTENDURLPRODUCTION,
cacheTime: 1000 * 60 * 15,
generate: true,
routes: [
...generateRoutesFromData({
langs: config.env.LANGS,
postTypes: postTypes,
dataPath: '../../../../../static/data',
bundle: 'basic',
homeSlug: config.env.HOMESLUG,
errorPrefix: config.env.ERROR_PREFIX
})
]
}
}


You can see that the generateLocalizedRoutes and the generateRoutesFromData methods are used to generate localized routes and is also taking post json files to generate routes from data (:slug).



--------- Edit 2:
I got it to run eventually.
I had to require all parts within the nuxt.config.js instead of importing them. I also resolved issues with the certificates. So I thought it was all cool 🚀.



BUT!!! 🚧:
Then I found out that I had my config file used within my post template.
So I thought I would also require the file within my template:
Like const config = require('~/config').
But then I would get this error:




[nuxt] Error while initializing app TypeError: ""exports" is read-only"




After some research, I found that is probably a thing when using common.js require and module.exports together with ES6 import/export within my project. (Probably linked to: https://github.com/FranckFreiburger/vue-pdf/issues/1).



So how could I still use my config.js when running nuxt programmatically (with require) and then also within my app?



I am glad to hear any ideas on this...
Cheers







vue.js https server nuxt.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 at 2:35







Merc

















asked Jan 19 at 18:19









MercMerc

82511332




82511332













  • Show the whole nuxt.config.js

    – Styx
    Jan 19 at 20:03











  • What nuxt version?

    – Aldarund
    Jan 19 at 20:59











  • @Aldarund Newest nuxt version: 2.3.4

    – Merc
    Jan 19 at 23:16











  • @Styx I edited my question and added my nuxt config

    – Merc
    Jan 19 at 23:16











  • I also tried to add dev: (process.env.NODE_ENV !== 'production') to my nuxt.config.js as indicated here, but no success: nuxtjs.org/api/configuration-dev#the-dev-property

    – Merc
    Jan 19 at 23:24



















  • Show the whole nuxt.config.js

    – Styx
    Jan 19 at 20:03











  • What nuxt version?

    – Aldarund
    Jan 19 at 20:59











  • @Aldarund Newest nuxt version: 2.3.4

    – Merc
    Jan 19 at 23:16











  • @Styx I edited my question and added my nuxt config

    – Merc
    Jan 19 at 23:16











  • I also tried to add dev: (process.env.NODE_ENV !== 'production') to my nuxt.config.js as indicated here, but no success: nuxtjs.org/api/configuration-dev#the-dev-property

    – Merc
    Jan 19 at 23:24

















Show the whole nuxt.config.js

– Styx
Jan 19 at 20:03





Show the whole nuxt.config.js

– Styx
Jan 19 at 20:03













What nuxt version?

– Aldarund
Jan 19 at 20:59





What nuxt version?

– Aldarund
Jan 19 at 20:59













@Aldarund Newest nuxt version: 2.3.4

– Merc
Jan 19 at 23:16





@Aldarund Newest nuxt version: 2.3.4

– Merc
Jan 19 at 23:16













@Styx I edited my question and added my nuxt config

– Merc
Jan 19 at 23:16





@Styx I edited my question and added my nuxt config

– Merc
Jan 19 at 23:16













I also tried to add dev: (process.env.NODE_ENV !== 'production') to my nuxt.config.js as indicated here, but no success: nuxtjs.org/api/configuration-dev#the-dev-property

– Merc
Jan 19 at 23:24





I also tried to add dev: (process.env.NODE_ENV !== 'production') to my nuxt.config.js as indicated here, but no success: nuxtjs.org/api/configuration-dev#the-dev-property

– Merc
Jan 19 at 23:24












1 Answer
1






active

oldest

votes


















0














Well, just to close this:
My problem resulted from running nuxt as a node app, which does not understand ES6 import statements, which appeared in my nuxt config.



So I had to rewrite things to work with commons.js (require).



This works for now.
(I also tried to run babel-node when starting the server.js, but had no success. Does not mean this did not work, I just wasn't keen on trying harder).



Thanks for the comments.
cheers






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54270053%2frun-nuxt-on-https-locally-problem-with-nuxt-config-js%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Well, just to close this:
    My problem resulted from running nuxt as a node app, which does not understand ES6 import statements, which appeared in my nuxt config.



    So I had to rewrite things to work with commons.js (require).



    This works for now.
    (I also tried to run babel-node when starting the server.js, but had no success. Does not mean this did not work, I just wasn't keen on trying harder).



    Thanks for the comments.
    cheers






    share|improve this answer




























      0














      Well, just to close this:
      My problem resulted from running nuxt as a node app, which does not understand ES6 import statements, which appeared in my nuxt config.



      So I had to rewrite things to work with commons.js (require).



      This works for now.
      (I also tried to run babel-node when starting the server.js, but had no success. Does not mean this did not work, I just wasn't keen on trying harder).



      Thanks for the comments.
      cheers






      share|improve this answer


























        0












        0








        0







        Well, just to close this:
        My problem resulted from running nuxt as a node app, which does not understand ES6 import statements, which appeared in my nuxt config.



        So I had to rewrite things to work with commons.js (require).



        This works for now.
        (I also tried to run babel-node when starting the server.js, but had no success. Does not mean this did not work, I just wasn't keen on trying harder).



        Thanks for the comments.
        cheers






        share|improve this answer













        Well, just to close this:
        My problem resulted from running nuxt as a node app, which does not understand ES6 import statements, which appeared in my nuxt config.



        So I had to rewrite things to work with commons.js (require).



        This works for now.
        (I also tried to run babel-node when starting the server.js, but had no success. Does not mean this did not work, I just wasn't keen on trying harder).



        Thanks for the comments.
        cheers







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 25 at 10:20









        MercMerc

        82511332




        82511332






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54270053%2frun-nuxt-on-https-locally-problem-with-nuxt-config-js%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Callistus III

            Ostreoida

            Plistias Cous