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

时间:2016-09-24 21:59:03

标签: javascript webpack

我想在我的index.js文件中包含sequence.js,我收到以下错误:

   ./src/js/sequence.js中的错误找不到模块:错误:无法解析   模块'imagesLoaded'在/ home / jdellaria / Desktop / Musicpack / src / js @   ./src/js/sequence.js 1144:95-143

      ./src/js/sequence.js中的错误找不到模块:错误:无法解析   模块'Hammer'在/ home / jdellaria / Desktop / Musicpack / src / js @   ./src/js/sequence.js 1144:95-143这是我的配置

webpack.config.js

// var webpack = require('webpack');
var path = require('path');
// webpack.config.js
var config = {
    entry: './src',
     resolve: {
      root: path.resolve('./src'),
      extenstions: ['', '.js'],
      moduleDirectories: ['node_modules']
    },
    output: {
        path: './dist',
        filename: 'my-app.js'
    },
    externals:[
        require('webpack-require-http')
    ],
    module: 
    {
      loaders: 
      [
       { test: /\.css$/, loaders: ['style', 'css'] }, // Note that the order is important here, it means that 'style-loader' will be applied to the ouput of 'css-loader'
    { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/, query: {presets: ['es2015']}},
//        { test: /\.js$/, loaders: ['babel']  },     // note that specifying 'babel' or 'babel-loader' is equivalent for Webpack
    { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,  loader: "url-loader?limit=10000&minetype=application/font-woff" },
    { test: /\.(jpe?g|png|gif|svg)$/, loader: 'url-loader?limit=10000&name=[path][name].[ext]'},
    { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }

  ]
}
}
module.exports = config;

index.js

require("!style!css!./css/styley.css");
require("./js/sequence.js");

console.log('Hello Webpack!');
document.write("It works.");
var greet = require('./greet');   // Import the greet function
greet('Webpack Jon');

的index.html

<html>
    <head>
    <script type="text/javascript" src="./dist/my-app.js"></script>
    </head>
    <body>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

Sequence.js使用AMD模块,它希望解析node_modules目录中的模块。而不是直接在/ js文件夹中引用脚本,将其安装为节点模块:

npm install sequencejs

然后在index.js

中要求它
require("sequencejs");