title: Webpack + Express + EJS: Error: Cannot find module "."
body: <p>I'm writing an express web app with webpack, typescript and ejs. When hitting one of the routes that's supposed to serve a .ejs file I get the following error:</p>
  
  <pre><code>Error: Cannot find module "."
     at webpackMissingModule (/Users/max/Development/test/express-webpack/dist/server.js:20669:74)
     at new View (/Users/max/Development/test/express-webpack/dist/server.js:20669:152)
     at EventEmitter.render (/Users/max/Development/test/express-webpack/dist/server.js:18776:12)
     at ServerResponse.render (/Users/max/Development/test/express-webpack/dist/server.js:20479:7)
     at /Users/max/Development/test/express-webpack/dist/server.js:25508:7
     at Layer.handle [as handle_request] (/Users/max/Development/test/express-webpack/dist/server.js:4524:5)
     at next (/Users/max/Development/test/express-webpack/dist/server.js:4743:13)
     at Route.dispatch (/Users/max/Development/test/express-webpack/dist/server.js:4724:3)
     at Layer.handle [as handle_request] (/Users/max/Development/test/express-webpack/dist/server.js:4524:5)
     at /Users/max/Development/test/express-webpack/dist/server.js:4054:22
  </code></pre>
  
  <p>Here's the code:</p>
  
  <h2>package.json:</h2>
  
  <pre><code>{
    "name": "express-webpack",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" &amp;&amp; exit 1"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
      "awesome-typescript-loader": "^3.0.0-beta.18",
      "copy-webpack-plugin": "^4.0.1",
      "debug": "^2.6.0",
      "ejs": "^2.5.5",
      "express": "^4.14.0",
      "json-loader": "^0.5.4",
      "source-map-loader": "^0.1.6",
      "webpack": "^2.2.0-rc.3"
    }
  }
  </code></pre>
  
  <h2>webpack.config.js</h2>
  
  <pre><code>var CopyWebpackPlugin = require('copy-webpack-plugin');
  
  module.exports = {
      entry: __dirname + "/src/index.js",
      target: "node",
      output: {
          filename: "server.js",
          path: __dirname + "/dist"
      },
  
      // Enable sourcemaps for debugging webpack's output.
      devtool: "source-map",
  
      resolve: {
          // Add '.ts' and '.tsx' as resolvable extensions.
          extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
      },
  
      module: {
          rules: [
              // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
              { test: /\.tsx?$/, loader: "awesome-typescript-loader" },
              { test: /\.json$/, loader: 'json-loader' },
  
              // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
              { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
          ]
      },
  
      plugins: [
          new CopyWebpackPlugin([
              { from: 'src/views', to: 'views' }
          ])
      ],
  
      node: {
        fs: "empty"
      }
  };
  </code></pre>
  
  <h2>src/index.js</h2>
  
  <pre><code>var express = require('express');
  
  var app = express();
  app.set("view engine", "ejs");
  app.set("views", "./views");
  app.get('/', function(req, res, next){
    res.render('index'); // &lt;-- error originates here AFAIK
  });
  app.listen(8000);
  </code></pre>
  
  <h2>views/index.ejs</h2>
  
  <pre><code>hello world
  </code></pre>
  
  <h2>Reproduction steps:</h2>
  
  <ul>
  <li>Run <code>webpack</code> to build the project</li>
  <li>Start the server with <code>node dist/server.js</code></li>
  <li>Visit <code>http://localhost:8000</code></li>
  <li>Expect to see the contents of index.ejs, instead get above stack trace</li>
  </ul>
  
  <p>Any idea what's going wrong?</p>