Webpack:错误:调试失败。错误的表达

时间:2018-07-10 08:04:48

标签: node.js reactjs typescript webpack

在尝试构建开发版以及向项目添加打字稿文件后,我一直收到此错误。

Module build failed (from ./node_modules/ts-loader/index.js):
Error: Debug Failure. False expression.

我已经尝试过 npm我的打字稿,但仍然遇到相同的错误。

package.json

{
  "name": "webpack-demo",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
    "build": "webpack -d"
  },
  "devDependencies": {},
  "dependencies": {
    "@types/node": "^10.5.1",
    "css-loader": "^0.28.11",
    "global": "^4.3.2",
    "node-sass": "^4.9.1",
    "sass-loader": "^7.0.3",
    "style-loader": "^0.21.0",
    "ts-loader": "^4.4.2",
    "typescript": "^2.9.2",
    "webpack": "^4.15.1",
    "webpack-cli": "^3.0.8"
  }
}

webpack.config.js

const path = require('path');
var webpack = require('webpack');
module.exports = {
    entry: './src/index.ts',
     mode: 'production',
     module: {
             rules: [{
                 test: /\.tsx?$/,
                 use: 'ts-loader',
                 exclude: /node_modules/
             },
             {
                 test: /\.scss$/,
                 use: ['style-loader', 'css-loader', 'sass-loader'],
                 exclude: /node_modules/
             }
            ],
         },
    resolve: {
             extensions: ['.tsx', '.ts', '.js','.css','.scss']
         },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'main.js'
    }
}

1 个答案:

答案 0 :(得分:0)

mode: 'production'中删除webpack.config.js似乎可以解决问题,但是随后必须在构建脚本中添加-d