s-panferov / awesome-typescript-loader

Awesome TypeScript loader for webpack
Other
2.35k stars 179 forks source link

"events" module breaks awesome-typescript-loader #643

Open ysulyma opened 5 years ago

ysulyma commented 5 years ago

Minimal working example

// index.ts
import * as EventEmitter from "events";
console.log(EventEmitter);

// package.json
{
  "name": "mwe",
  "version": "1.0.0",
  "description": "Minimal working example for \"events\" bug in awesome-typescript-loader and webpack",
  "dependencies": {
    "@types/events": "^3.0.0",
    "awesome-typescript-loader": "^5.2.1",
    "events": "^3.0.0",
    "typescript": "^3.6.2",
    "webpack": "^4.39.3",
    "webpack-cli": "^3.3.7"
  }
}

// webpack.config.js
const webpack = require("webpack");
const {CheckerPlugin} = require("awesome-typescript-loader");

module.exports = {
  entry: `${__dirname}/index.ts`,
  output: {
    filename: "output.js",
    path: __dirname,
    library: "Test"
  },

  mode: process.env.NODE_ENV,

  module: {
    rules: [
     {
        test: /\.[jt]sx?$/,
        loader: "awesome-typescript-loader",
        options: {
          configFileName: `${__dirname}/tsconfig.json`
        }
      }
    ]
  },

  plugins: [
    new CheckerPlugin()
  ],

  resolve: {
    extensions: ["*.js", ".ts"]
  }
};

// tsconfig.json
{
  "files": ["./index.ts"]
}

Steps to reproduce

Copy above files into a directory. Run

npm install
webpack --watch

This produces the output:

webpack is watching the files…

ℹ 「atl」: Using typescript@3.6.2 from typescript
ℹ 「atl」: Using tsconfig.json from mwe/tsconfig.json (in a forked process)
✖ 「atl」: Child process failed to process the request: TypeError: Cannot read property 'moduleAugmentations' of undefined
    at containsGlobalScopeAugmentation (mwe/node_modules/typescript/lib/typescript.js:93996:39)
    at isFileAffectingGlobalScope (mwe/node_modules/typescript/lib/typescript.js:94002:20)
    at Object.getAllDependencies (mwe/node_modules/typescript/lib/typescript.js:93932:41)
    at Object.result.getAllDependencies (mwe/node_modules/typescript/lib/typescript.js:94658:84)
    at processEmit (mwe/node_modules/awesome-typescript-loader/dist/checker/runtime.js:377:28)
    at process.<anonymous> (mwe/node_modules/awesome-typescript-loader/dist/checker/runtime.js:497:21)
    at process.emit (events.js:200:13)
    at emit (internal/child_process.js:876:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:9)
ℹ 「atl」: Checking started in a separate process...
Hash: c7622806a916fe92d7c1
Version: webpack 4.39.3
Time: 2054ms
Built at: 09/01/2019 12:50:57 AM
    Asset      Size  Chunks             Chunk Names
output.js  5.07 KiB    main  [emitted]  main
Entrypoint main = output.js
[./index.ts] 106 bytes {main} [built]
    + 1 hidden module

ERROR in ./node_modules/events/events.js
Module build failed: Error: Final loader (./node_modules/awesome-typescript-loader/dist/entry.js) didn't return a Buffer or String
    at mwe/node_modules/webpack/lib/NormalModule.js:330:18
    at mwe/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (mwe/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at iterateNormalLoaders (mwe/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
    at mwe/node_modules/loader-runner/lib/LoaderRunner.js:236:3
    at context.callback (mwe/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
 @ ./index.ts 3:19-36
ℹ 「atl」: Time: 174ms