找不到模块:错误:无法解析模块'模块'

时间:2016-11-24 06:20:11

标签: javascript node.js reactjs webpack babeljs

我想从变量字符串

加载模块
var abc = './../containers/BlankContainer';
require(abc);

但它找不到模块,所以我安装了'require-from-string'来自npm的模块。 现在当我构建它时给出了错误

ERROR in ./~/require-from-string/index.js Module not found: Error: Cannot resolve module 'module' in D:\Nilay\RnD\node_modules\require-from-string @ ./~/require-from-string/index.js 3:13-30

我发现它是webpack问题,这是我的webpack配置:

const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin')
var entry = [path.resolve(__dirname, 'app/bootstrap.js')];
var output = {
  path: path.resolve(__dirname, 'public/dist'),
  filename: 'bundle-[name].js',
  publicPath: "dist/"
};

var modules = {
  loaders: [
    { test: /\.json$/, loader: "json-loader" },
    { test: /\.js$/, 
loader: ['babel-loader'], exclude: /node_modules/, query: { cacheDirectory: 'babel_cache', presets: ['react', 'es2015'] } },
    { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader!autoprefixer-loader") },
    { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader" },
    { test: /\.(woff|woff2)$/, loader: "file-loader" },
    { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader" },
    { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader" }
  ]
};

var plugins = [
  new ExtractTextPlugin("bundle.css"),
  new webpack.DefinePlugin({
    'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
  }),
  new webpack.ProvidePlugin({
    jQuery: 'jquery',
    $: 'jquery',
    jquery: 'jquery'
  }),
  new webpack.optimize.DedupePlugin(),
  new webpack.optimize.OccurenceOrderPlugin(),
  new webpack.optimize.UglifyJsPlugin({ // minimize/compress all js chunks
    compress: { warnings: false },
    mangle: false,
    sourcemap: false,
    beautify: false,
    dead_code: true
  })
]

module.exports = {
  entry: entry,
  output: output,
  stats: { colors: true },
  watch: true,
  module: modules,
  plugins: plugins,
  resolveLoader: {
    root: path.join(__dirname, 'node_modules')
  },
  resolve: {
    modules: [path.resolve(__dirname, '/app/routes'), 'node_modules/'],
    descriptionFiles: ['package.json'],
    extensions: ['', '.js', '.ts']
  }
};

我该如何解决?

0 个答案:

没有答案