Webpack-dev-server: resolve is not defined

Created on 4 May 2018  路  3Comments  路  Source: webpack/webpack-dev-server

  • Operating System: Linux
  • Node Version: v9.11.1
  • NPM Version: v5.6.0
  • webpack Version: v3.6.0
  • webpack-dev-server Version: v2.9.1
  • [x] This is a bug

Code

  // webpack.config.js
var path = require('path');
var webpack = require('webpack');

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.join(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [{
        test: /\.css$/,
        use: [
          'style-loader',
          'vue-style-loader',
          'css-loader'
        ],
      }, {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {}
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [resolve('node_modules/vue-octicon')],
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|jpeg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}

Expected Behavior

It should resolve the path directory.

Actual Behavior

It's throwing resolve is not defined error. This issue is coming when I am using vue-cli with webpack. And only when I run npm run build.

 path: path.join(__dirname, './dist'),
               ^

ReferenceError: resolve is not defined
    at Object.<anonymous> (/home/praveen/Baseblock/client_webpack/client_webpack/webpack.config.js:7:16)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at requireConfig (/home/praveen/Baseblock/client_webpack/client_webpack/node_modules/webpack/bin/convert-argv.js:97:18)
    at /home/praveen/Baseblock/client_webpack/client_webpack/node_modules/webpack/bin/convert-argv.js:104:17

For Bugs; How can we reproduce the behavior?

For Features; What is the motivation and/or use-case for the feature?

Most helpful comment

I was having this issue too, and how I solved it was by putting all of my __dirname paths declared inside the alias, like so :
Alias: {
scss: path.resolve(__dirname, 'src/scss/)
endpath: path.resolve(__dirname, 'src/dist/newjs/')
}

You can then reference the path name in the file later like this: 'scss/default.scss' and then the problem should be resolved. You can also export to the other react JS files using those alias names for shorter directory.

All 3 comments

Looks on your stacktrace, problem in your configuration file (/home/praveen/Baseblock/client_webpack/client_webpack/webpack.config.js:7:16).

I was having this issue too, and how I solved it was by putting all of my __dirname paths declared inside the alias, like so :
Alias: {
scss: path.resolve(__dirname, 'src/scss/)
endpath: path.resolve(__dirname, 'src/dist/newjs/')
}

You can then reference the path name in the file later like this: 'scss/default.scss' and then the problem should be resolved. You can also export to the other react JS files using those alias names for shorter directory.

I was having this issue too, and how I solved it was by putting all of my __dirname paths declared inside the alias, like so :
Alias: {
scss: path.resolve(__dirname, 'src/scss/)
endpath: path.resolve(__dirname, 'src/dist/newjs/')
}

You can then reference the path name in the file later like this: 'scss/default.scss' and then the problem should be resolved. You can also export to the other react JS files using those alias names for shorter directory.

thanks a lot锛孖 solve the problem by this way

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hnqlvs picture hnqlvs  路  3Comments

movie4 picture movie4  路  3Comments

eyakcn picture eyakcn  路  3Comments

MJ111 picture MJ111  路  3Comments

Ky6uk picture Ky6uk  路  3Comments