未找到多主模块中的错误:错误:无法解析模块' bundle.js'

时间:2016-12-05 23:40:01

标签: webpack bundle

我正在尝试将webpack添加到使用https://cosmicjs.com/平台构建的现有项目中。我已经包含了一个早期的Webpack.config.js文件,其中包含以下代码:

var path = require('path');

entry: path.resolve(__dirname, '/src/index.js'),
instead of:
entry: path.resolve(__dirname, 'src/index.js'),

module.exports = {
  devtool: 'eval',
  entry: './app.js',
  output: {
    path: __dirname + '/public/',
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      { test: /\.json$/, loader: 'json-loader' }
    ]
  },
  resolve: {
    extensions: ['', '.webpack.js', '.web.js', '.js']
  },
  node: {
    console: 'empty',
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }
};

在我的项目根目录中,我有一个app.js文件以及一个public\views\个文件夹。在views\内,我有index.html我称之为捆绑脚本:<script src="bundle.js"></script>。 bundle.js文件是根据上面的配置文件在public\文件夹中生成的。但是当我在终端中执行:webpack ./app.js bundle.js时,我收到以下错误:

Hash: f1c7ed9b1e871bc9daf0
Version: webpack 1.13.3
Time: 2112ms
    Asset     Size  Chunks             Chunk Names
bundle.js  1.31 MB       0  [emitted]  main
   [0] multi main 52 bytes {0} [built] [1 error]
   [1] ./app.js 544 bytes {0} [built]
    + 128 hidden modules

WARNING in ./~/express/lib/view.js
Critical dependencies:
78:29-56 the request of a dependency is an expression
 @ ./~/express/lib/view.js 78:29-56

ERROR in multi main
Module not found: Error: Cannot resolve module 'bundle.js' in /Users/elby/git/histamyn/cosmicapp-histamyn
 @ multi main

我觉得我正在做一些我看不到的非常明显的事情。很难将webpack添加到现有的动态项目中,因此可能会在某个地方发生冲突。我的app.js文件包含以下代码:

var express = require('express')
var app = express()
var hogan = require('hogan-express')
app.engine('html', hogan)
app.set('port', (process.env.PORT || 3000))
app.use('/', express.static(__dirname + '/public/'))
var Cosmic = require('cosmicjs')
var bucket_slug = process.env.COSMIC_BUCKET || 'stellar'
app.get('/', function(req, res) {
  Cosmic.getObjects({ bucket: { slug: bucket_slug } }, function(err, response) {
    res.locals.cosmic = response;
    res.render('index.html')
  })
});
app.listen(app.get('port'))
console.log('app loaded')

并运行http://localhost:3000/

下的views / index.html

0 个答案:

没有答案