Runtime Missing module error from UglifyJS plugin.

Do you want to request a feature or report a bug?

What is the current behavior?
I have a Typescript project that I’m trying to bundle with Webpack, but I keep getting a runtime missing module error from what appears to be an issue including UglifyJS.

Also, the log message doesn’t include the missing module file name:

"errorMessage": "Cannot find module \".\"",

If the current behavior is a bug, please provide the steps to reproduce.

To repro:

git clone
cd larynx-sample-highlow
git fetch
git checkout --track -b webpack origin/webpack
npm install
npm run webpack

then check build/larynx_bundle.js and search for UglifyJS.FILES. You should see a bunch of requires for files not included with the bundle as below:

var UglifyJS = exports;
var FILES = UglifyJS.FILES = [
    return /*require.resolve*/(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()));

What is the expected behavior?
Those files should be included in the bundle.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
Using Node v6.9.5, Npm 3.10.10, and latest webpack version.

It looks like webpack is looking at the directory structure of the Uglify-js node module.

├── bin
│   ├── extract-props.js
│   └── uglifyjs
├── lib
│   ├── ast.js
│   ├── compress.js
│   ├── mozilla-ast.js
│   ├── output.js
│   ├── parse.js
│   ├── propmangle.js
│   ├── scope.js
│   ├── sourcemap.js
│   ├── transform.js
│   └── utils.js
├── node_modules

This is my tsconfig.json

  "compilerOptions": {
    "outDir": "build/",
    "sourceMap": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "target": "es5",
    "types": ["node"],
    "declaration": true,
    "noImplicitAny": true,
    "removeComments": true,
    "rootDir": ".",
    "lib": ["es2015", "es2015.promise", "dom"]
  "include": [
  "exclude": [

and my webpack.config.json

let path = require('path');
let webpack = require('webpack');
let ZipPlugin = require('zip-webpack-plugin');

module.exports = {
    entry: './src/index.ts',
    output: {
        path: path.join(__dirname, 'build'),
        filename: 'larynx_bundle.js',
        libraryTarget: 'commonjs',
        umdNamedDefine: false
    externals: {
        "aws-sdk": "aws-sdk"
    devtool: 'source-map',
    target: 'node',
    plugins: [
        new ZipPlugin({
            fileOptions: {
                mtime: new Date(),
                mode: 0o100664,
                compress: true,
                forceZip64Format: false,
            pathPrefix: './',
    resolve: {
        extensions: ['.ts', '.js']
    module: {
        loaders: [
                test: /\.ts$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
                test: /\.js$/,
                loader: 'source-map-loader',
                exclude: /node_modules/,

Any advice?

Author: Fantashit

1 thought on “Runtime Missing module error from UglifyJS plugin.

  1. If I understand correctly as long as uglify-js relies directly on the filesystem internally it’s not webpack compliant.

    In create-react-app they’re using the uglify-es alternative, but it’s not maintained anymore, the right alternative now being terser.

    If uglify-js is a dependency of a dependency you don’t have control on, and if you are using yarn you can use its resolutions feature to use terser instead which maintains the same API:

      "resolutions": {
        "uglify-js": "npm:terser"
      dependencies: { ... }

Comments are closed.