nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.2k stars 246 forks source link

Cannot read property 'indexOf' of undefined: module.js 73:26 #244

Closed yubing24 closed 5 years ago

yubing24 commented 5 years ago

Version

v5.1.0

Reproduction link

https://github.com/DancesportSoftware/das-frontend/tree/develop

Steps to reproduce

The actual dependency is v5.3.6, but there is no option in the version dropdown selection.

What is expected ?

Should build correctly without any error

What is actually happening?

> das-frontend@1.0.0 build C:\Users\houyu\WebstormProjects\das-frontend
> nuxt build

 FATAL  Cannot read property 'indexOf' of undefined                                                                                                                            09:43:55

  at https (node_modules\@nuxtjs\axios\lib\module.js:73:26)
  at ModuleContainer.axiosModule (node_modules\@nuxtjs\axios\lib\module.js:74:23)
  at ModuleContainer.addModule (node_modules\@nuxt\core\dist\core.js:190:34)
  at promise.then (node_modules\@nuxt\utils\dist\utils.js:1790:43)
  at <anonymous>

   ╭────────────────────────────────────────────────────────────╮
   │                                                            │
   │   ✖ Nuxt Fatal Error                                       │
   │                                                            │
   │   TypeError: Cannot read property 'indexOf' of undefined   │
   │                                                            │
   ╰────────────────────────────────────────────────────────────╯

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! das-frontend@1.0.0 build: `nuxt build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the das-frontend@1.0.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:
npm ERR!     C:\Users\houyu\AppData\Roaming\npm-cache\_logs\2019-04-30T14_43_55_164Z-debug.log

Additional comments?

package.json:

{
  "name": "das-frontend",
  "version": "1.0.0",
  "description": "A frontend viewport for DAS",
  "author": "Justin Chiou <chiou.kai@gmail.com>",
  "contributors": [
    "Yubing Hou <houyubing24@gmail.com>",
    "Jessica Wang",
    "Kevin Enario"
  ],
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "lint": "tslint --fix --ext .ts,.js,.vue --ignore-path .gitignore .",
    "dev": "nuxt",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "precommit": "npm run lint",
    "post-update": "yarn upgrade --latest"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.15",
    "@fortawesome/free-brands-svg-icons": "^5.7.2",
    "@fortawesome/free-regular-svg-icons": "^5.7.2",
    "@fortawesome/free-solid-svg-icons": "^5.7.2",
    "@nuxtjs/axios": "^5.3.6",
    "@nuxtjs/markdownit": "^1.2.3",
    "@nuxtjs/moment": "^1.2.0",
    "@nuxtjs/proxy": "^1.3.2",
    "@types/node": "^11.11.4",
    "cookieparser": "^0.1.0",
    "firebase": "^5.8.4",
    "js-cookie": "^2.2.0",
    "jwt-decode": "^2.2.0",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "node-dir": "^0.1.17",
    "nuxt": "^2.6.3",
    "ts-node": "^8.0.3",
    "tslint": "^5.14.0",
    "vue-property-decorator": "^7.3.0",
    "vuetify": "^1.5.13",
    "vuex-class": "^0.3.1",
    "vuex-persist": "^2.0.0",
    "vuex-persistedstate": "^2.5.4"
  },
  "devDependencies": {
    "@babel/polyfill": "^7.2.5",
    "@nuxt/typescript": "^2.5.0",
    "babel-eslint": "^8.2.6",
    "babel-plugin-transform-imports": "^1.5.1",
    "eslint": "^4.19.1",
    "eslint-friendly-formatter": "^3.0.0",
    "eslint-loader": "^1.7.1",
    "eslint-plugin-vue": "^4.7.1",
    "node-sass": "^4.11.0",
    "prettier": "^1.16.4",
    "push-dir": "^0.4.1",
    "sass-loader": "^7.1.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.1",
    "tslint-config-standard": "^8.0.1",
    "vue-cli-plugin-vuetify": "^0.1.6"
  }
}
This bug report is available on Nuxt community (#c242)
yubing24 commented 5 years ago

I think I figured out the issue. In nuxt.config.js, instead of using:

modules: [
    [ '@nuxtjs/axios',
      {
        baseURL: process.env.BASE_URL,
        https: true,
        retries: 3
      }
    ]
]

I need to change it to:

modules: [
    [ '@nuxtjs/axios',
      {
        baseURL: process.env.BASE_URL || 'https://my.api.endpoint',
        https: true,
        retries: 3
      }
    ]
]

Is there a way that I can inject process.env.BASE_URL during build or generate?