0

我尝试了 pug.js,然后决定不使用它并卸载它。现在,当我启动 webpack dev-server 时,我收到以下错误:

Unhandled rejection Error: Cannot find module 'pug'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at /vagrant/myproject/frontend/node_modules/consolidate/lib/consolidate.js:825:33
    at /vagrant/myproject/frontend/node_modules/consolidate/lib/consolidate.js:144:5
    at promisify (/vagrant/myproject/frontend/node_modules/consolidate/lib/consolidate.js:137:10)
    at Function.exports.pug.render (/vagrant/myproject/frontend/node_modules/consolidate/lib/consolidate.js:821:10)
    at Object.module.exports (/vagrant/myproject/frontend/node_modules/vue-loader/lib/template-compiler/preprocessor.js:26
:20)
    at LOADER_EXECUTION (/vagrant/myproject/frontend/node_modules/loader-runner/lib/LoaderRunner.js:119:14)
    at runSyncOrAsync (/vagrant/myproject/frontend/node_modules/loader-runner/lib/LoaderRunner.js:120:4)
    at iterateNormalLoaders (/vagrant/myproject/frontend/node_modules/loader-runner/lib/LoaderRunner.js:229:2)
    at iterateNormalLoaders (/vagrant/myproject/frontend/node_modules/loader-runner/lib/LoaderRunner.js:218:10)

因此,我尝试从 node_modules/consolidate/lib/consolidate.js 中删除以下行,但没有帮助:

/**
 * Pug support. (formerly Jade)
 */

exports.pug = function(path, options, fn){
  return promisify(fn, function (fn) {
    var engine = requires.pug;
    if (!engine) {
      try {
        engine = requires.pug = require('pug');
      } catch (err) {
        try {
          engine = requires.pug = require('then-pug');
        } catch (otherError) {
          throw err;
        }
      }
    }

    try {
      var tmpl = cache(options) || cache(options, engine.compileFile(path, options));
      fn(null, tmpl(options));
    } catch (err) {
      fn(err);
    }
  });
};

/**
 * Pug string support.
 */

exports.pug.render = function(str, options, fn){
  return promisify(fn, function (fn) {
    var engine = requires.pug;
    if (!engine) {
      try {
        engine = requires.pug = require('pug');
      } catch (err) {
        try {
          engine = requires.pug = require('then-pug');
        } catch (otherError) {
          throw err;
        }
      }
    }

    try {
      var tmpl = cache(options) || cache(options, engine.compile(str, options));
      fn(null, tmpl(options));
    } catch (err) {
      fn(err);
    }
  });
};

webpack.base.conf.js:

var path = require('path')
var utils = require('./utils')
var config = require('../config')
var vueLoaderConfig = require('./vue-loader.conf')

function resolve (dir) {
  return path.join(__dirname, '..', dir)
}

module.exports = {
  entry: {
    app: './src/main.js'
  },
  output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production'
      ? config.build.assetsPublicPath
      : config.dev.assetsPublicPath
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
    }
  },
  module: {
    rules: [
      {
        test: /\.(js|vue)$/,
        loader: 'eslint-loader',
        enforce: 'pre',
        include: [resolve('src'), resolve('test')],
        options: {
          formatter: require('eslint-friendly-formatter')
        }
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [resolve('src'), resolve('test')]
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('img/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('media/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      }
    ]
  }
}

webpack.dev.conf.js:

var utils = require('./utils')
var webpack = require('webpack')
var config = require('../config')
var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')

// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
  baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
})

module.exports = merge(baseWebpackConfig, {
  module: {
    rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
  },
  // cheap-module-eval-source-map is faster for development
  devtool: '#cheap-module-eval-source-map',
  plugins: [
    new webpack.DefinePlugin({
      'process.env': config.dev.env
    }),
    // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
    // https://github.com/ampedandwired/html-webpack-plugin
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.html',
      inject: true
    }),
    new FriendlyErrorsPlugin()
  ]
})

请帮我找到它的配置位置。我需要摆脱 pug 及其依赖项。谢谢。

4

1 回答 1

0

感谢@Axnyff,我终于发现我没有在我的一个 Vue 组件中删除模板 lang="pug" 。

于 2017-10-05T16:46:23.753 回答