错误:无法找到模块'表达'

时间:2017-07-15 14:29:00

标签: javascript express typescript webpack

我使用webpack编译我的Express应用程序(用TypeScript编写)。但是我在运行编译文件时遇到了一些麻烦。

webpack.config.json

const root = require('app-root-path').path;
module.exports = {
    entry: `${root}/server/server.ts`,
    target: 'node',
    externals: [
        /^[a-z\-0-9]+$/ 
    ],
    output: {
        filename: 'compiled.js',
        path: `${root}`,
        libraryTarget: "commonjs"
    },
    resolve: {
        extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
    },
    module: {
        loaders: [{
            test: /\.tsx?$/,
            exclude: `/node_modules/`,
            loader: 'ts-loader'
        }]
    }
}

当我尝试运行已编译的文件时,我得到了这个:

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/compiled.js:717:18)
    at __webpack_require__ (/compiled.js:20:30)
    at Object.<anonymous> (/compiled.js:644:17)
    at Object.<anonymous> (/compiled.js:705:30)
    at __webpack_require__ (/compiled.js:20:30)
    at /compiled.js:63:18

0 个答案:

没有答案