Search code examples
reactjstypescriptwebpackfluxts-loader

webpack cannot resolve flux/utils


I have a OS project written in TypeScript that I am migrating toward webpack,

However, I cannot build the project currently due to this error

ERROR in ./src/store/GigaStore.ts
Module not found: Error: Cannot resolve module 'flux/utils' in /home/erfangc/GigaGrid/src/store
 @ ./src/store/GigaStore.ts 11:16-37

Project Located Here https://github.com/erfangc/GigaGrid/tree/webpack

Here is what I've done to get to this point:

  • Using ts-loader
  • The line that imports flux/utils is: import FluxUtils = require('flux/utils');
  • I've tried alternative import syntax to no avail
  • I've tried adding a resolve.alias section for flux/utils: 'ABSOLUTE_PATH'

The file definitely exists under node_modules and other libraries that I depend on seems to be bundled fine

Any help is greatly appreciated ...

webpack.config.js reproduced here from the repo

module.exports = {
    entry: "./src/index.ts",
    output: {
        path: "./dist",
        libraryTarget: "umd",
        library: "GigaGrid",
        filename: "giga-grid.js"
    },
    resolve: {
        extensions: ['', 'webpack.js', '.web.js', 'js', '.ts', '.tsx']
    },
    module: {
        loaders: [
            {
                test: /\.tsx?$/, loader: "ts-loader"
            },
            {
                test: /\.css$/, loader: "style-loader!css-loader"
            },
            {
                test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
                loader: "url?limit=10000&mimetype=application/font-woff"
            }, {
                test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
                loader: "url?limit=10000&mimetype=application/font-woff"
            }, {
                test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
                loader: "url?limit=10000&mimetype=application/octet-stream"
            }, {
                test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
                loader: "file"
            }, {
                test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
                loader: "url?limit=10000&mimetype=image/svg+xml"
            }
        ]
    },
    externals: {
        "react": {
            commonjs: 'react',
            commonjs2: 'react',
            amd: 'react',
            root: 'React'
        },
        "react-dom": {
            commonjs: 'react-dom',
            commonjs2: 'react-dom',
            amd: 'react-dom',
            root: 'ReactDOM'
        }
    }
};

Solution

  • You have a misprint in your resolve.extensions section. Extension name for js files must start with dot:

    resolve: {
        extensions: ['', 'webpack.js', '.web.js', '.js', '.ts', '.tsx']
    },
    

    So, js modules couldn't be resolved.