Repository: nuxt/nuxt.js
Pull request #8134 (2020-09-30 12:35:57)

fix(cli): mode deprecation with explicit spa or universal flag
<!--- Provide a general summary of your changes in the title above -->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [x] Bug fix (a non-breaking change which fixes an issue)


## Description
<!--- Describe your changes in detail -->
<!--- Why is this change required? What problem does it solve? -->
<!--- If it resolves an open issue, please link to the issue here. For example "Resolves: #1337" -->

Fix https://github.com/nuxt/nuxt.js/issues/8133
Fix https://github.com/nuxt/nuxt.js/pull/8044#issuecomment-700163823

Assign `ssr` instead of `mode` when using `--spa` or `--universal` flag in cli

## Checklist:
<!--- Put an `x` in all the boxes that apply. -->
<!--- If your change requires a documentation PR, please link it appropriately -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [x] I have added tests to cover my changes (if not applicable, please state why)
- [x] All new and existing tests are passing.



codecov-commenter: # [Codecov](https://codecov.io/gh/nuxt/nuxt.js/pull/8134?src=pr&el=h1) Report
> Merging [#8134](https://codecov.io/gh/nuxt/nuxt.js/pull/8134?src=pr&el=desc) into [dev](https://codecov.io/gh/nuxt/nuxt.js/commit/61e93d01f96adf505025fafa85d4054658758e8b?el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/nuxt/nuxt.js/pull/8134/graphs/tree.svg?width=650&height=150&src=pr&token=nGD1PtMB3M)](https://codecov.io/gh/nuxt/nuxt.js/pull/8134?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##              dev    #8134      +/-   ##
==========================================
+ Coverage   68.91%   68.93%   +0.01%     
==========================================
  Files          91       91              
  Lines        3851     3853       +2     
  Branches     1048     1049       +1     
==========================================
+ Hits         2654     2656       +2     
  Misses        972      972              
  Partials      225      225              
```

| Flag | Coverage Δ | |
|---|---|---|
| #unittests | `68.93% <100.00%> (+0.01%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/nuxt/nuxt.js/pull/8134?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packages/cli/src/utils/config.js](https://codecov.io/gh/nuxt/nuxt.js/pull/8134/diff?src=pr&el=tree#diff-cGFja2FnZXMvY2xpL3NyYy91dGlscy9jb25maWcuanM=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/nuxt/nuxt.js/pull/8134?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/nuxt/nuxt.js/pull/8134?src=pr&el=footer). Last update [61e93d0...0ef1c57](https://codecov.io/gh/nuxt/nuxt.js/pull/8134?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/examples/layout-transitions/package.json b/examples/layout-transitions/package.json
index 480616cf2..b281ff9de 100644
--- a/examples/layout-transitions/package.json
+++ b/examples/layout-transitions/package.json
@@ -1,7 +1,6 @@
 {
   "name": "example-layout-transitions",
   "dependencies": {
-    "axios": "^0.19.0",
     "nuxt": "latest"
   },
   "scripts": {
diff --git a/examples/layout-transitions/pages/users-2.vue b/examples/layout-transitions/pages/users-2.vue
index e8380afdb..665ba8f15 100644
--- a/examples/layout-transitions/pages/users-2.vue
+++ b/examples/layout-transitions/pages/users-2.vue
@@ -30,12 +30,10 @@
 </template>
 
 <script>
-import axios from 'axios'
-
 export default {
   async asyncData ({ query }) {
     const page = +(query.page || 1)
-    const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
+    const data = await fetch(`https://reqres.in/api/users?page=${page}`).then(res => res.json())
     return {
       page,
       totalPages: data.total_pages,
@@ -50,7 +48,7 @@ export default {
   watch: {
     async '$route.query.page' (page) {
       this.$nuxt.$loading.start()
-      const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
+      const data = await fetch(`https://reqres.in/api/users?page=${page}`).then(res => res.json())
       this.users = data.data
       this.transitionName = this.getTransitionName(page)
       this.page = +(page || 1)
diff --git a/examples/layout-transitions/pages/users.vue b/examples/layout-transitions/pages/users.vue
index 7cccaca33..52609b235 100644
--- a/examples/layout-transitions/pages/users.vue
+++ b/examples/layout-transitions/pages/users.vue
@@ -28,8 +28,6 @@
 </template>
 
 <script>
-import axios from 'axios'
-
 export default {
   // Watch for $route.query.page to call Component methods (asyncData, fetch, validate, layout, etc.)
   watchQuery: ['page'],
@@ -42,7 +40,7 @@ export default {
   },
   async asyncData ({ query }) {
     const page = +(query.page || 1)
-    const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
+    const data = await fetch(`https://reqres.in/api/users?page=${page}`).then(res => res.json())
     return {
       page,
       totalPages: data.total_pages,
diff --git a/packages/cli/src/utils/config.js b/packages/cli/src/utils/config.js
index ed09dcc74..db1bece71 100644
--- a/packages/cli/src/utils/config.js
+++ b/packages/cli/src/utils/config.js
@@ -1,7 +1,6 @@
 import path from 'path'
 import defaultsDeep from 'lodash/defaultsDeep'
 import { loadNuxtConfig as _loadNuxtConfig, getDefaultNuxtConfig } from '@nuxt/config'
-import { MODES } from '@nuxt/utils'
 
 export async function loadNuxtConfig (argv, configContext) {
   const rootDir = path.resolve(argv._[0] || '.')
@@ -18,9 +17,11 @@ export async function loadNuxtConfig (argv, configContext) {
     }
   })
 
-  // Nuxt Mode
-  options.mode =
-    (argv.spa && MODES.spa) || (argv.universal && MODES.universal) || options.mode
+  if (argv.spa === true) {
+    options.ssr = false
+  } else if (argv.universal === true) {
+    options.ssr = true
+  }
 
   // Server options
   options.server = defaultsDeep({
diff --git a/packages/generator/src/generator.js b/packages/generator/src/generator.js
index 5f72dcb87..25b208723 100644
--- a/packages/generator/src/generator.js
+++ b/packages/generator/src/generator.js
@@ -104,7 +104,13 @@ export default class Generator {
     if (this.options.router.mode === 'hash') {
       routes = ['/']
     } else {
-      routes = flatRoutes(this.getAppRoutes())
+      try {
+        routes = flatRoutes(this.getAppRoutes())
+      } catch (err) {
+        // Case: where we use custom router.js
+        // https://github.com/nuxt-community/router-module/issues/83
+        routes = ['/']
+      }
     }
     routes = routes.filter(route => this.shouldGenerateRoute(route))
     routes = this.decorateWithPayloads(routes, generateRoutes)


Test patch:
diff --git a/packages/cli/test/unit/utils.test.js b/packages/cli/test/unit/utils.test.js
index 4184c15b4..e3eba23c9 100644
--- a/packages/cli/test/unit/utils.test.js
+++ b/packages/cli/test/unit/utils.test.js
@@ -1,5 +1,5 @@
 import { getDefaultNuxtConfig } from '@nuxt/config'
-import { TARGETS, MODES } from '@nuxt/utils'
+import { TARGETS } from '@nuxt/utils'
 import { consola } from '../utils'
 import { loadNuxtConfig } from '../../src/utils/config'
 import * as utils from '../../src/utils'
@@ -25,7 +25,8 @@ describe('cli/utils', () => {
 
     const options = await loadNuxtConfig(argv)
     expect(options.rootDir).toBe(process.cwd())
-    expect(options.mode).toBe(MODES.universal)
+    expect(options.mode).toBeUndefined()
+    expect(options.ssr).toBe(true)
     expect(options.server.host).toBe('localhost')
     expect(options.server.port).toBe(3000)
     expect(options.server.socket).not.toBeDefined()
@@ -41,7 +42,8 @@ describe('cli/utils', () => {
     const options = await loadNuxtConfig(argv)
     expect(options.testOption).toBe(true)
     expect(options.rootDir).toBe('/some/path')
-    expect(options.mode).toBe(MODES.spa)
+    expect(options.mode).toBe('supercharged')
+    expect(options.ssr).toBe(false)
     expect(options.server.host).toBe('nuxt-host')
     expect(options.server.port).toBe(3001)
     expect(options.server.socket).toBe('/var/run/nuxt.sock')