Home

Issue: 2793

webpack alias not working

[issue link]

Here’s the extension as suggested in community here:

module.exports = {
  /* Headers of the page */
  head: {
    title: '{{ name }}',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '{{ description }}' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /* Customize the progress bar color */
  loading: { color: '#3B8070' },
  /* build stuff */
  build: {
    extend (config, { isDev, isClient }) {
        config.resolve = module.resolve || {}
        config.resolve.alias = module.resolve.alias || {}
        config.resolve.alias['@components']= './components/'
    }
  }
}

And here’s the not so lucky output when running npm run-script build:

ERROR in ./node_modules/babel-loader/lib?{"babelrc":false,"cacheDirectory":false,"presets":[["my app path//node_modules//babel-preset-vue-app//dist//index.common.js",{"targets":{"ie":9,"uglify":true}}]]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./pages/index.vue
Module not found: Error: Can't resolve '@components/AppLogo.vue' in 'my app path\pages'
 @ ./node_modules/babel-loader/lib?{"babelrc":false,"cacheDirectory":false,"presets":[["my app path//node_modules//babel-preset-vue-app//dist//index.common.js",{"targets":{"ie":9,"uglify":true}}]]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./pages/index.vue 26:0-46
 @ ./pages/index.vue
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

Any ideas on what’s going on? I noticed a couple of things while battling this:

  1. There are no resolve or alias objects, so they have to be added altogether.
  2. Replacing the @ with ~ does not help.
  3. If instead of ./components, path.resolve(__dirname, './components/') or path.join(__dirname, './components/') are used still would not work.

Using nuxt 1.3.0 which uses webpack 3.10.0 so I’m confused as to what could be wrong here. Also using windows 10.

This question is available on Nuxt.js community (#c2426)