s-panferov / awesome-typescript-loader

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

ERROR in awesome-typescript-loader #619

Open potapovnikita opened 5 years ago

potapovnikita commented 5 years ago

I'm get a error: ERROR in ./ClientApp/src/utils/utils.ts Module build failed: Error: Final loader (./node_modules/awesome-typescript-loader/dist/entry.js) didn't return a Buffer or String

utils.ts: export function removeRouteParams() {window.history.replaceState({}, document.title, '/');}

If i'm remove window.history, then error is dissapeared

darklightcode commented 5 years ago

Try adding "dom" lib into the tsconfig.json compilerOptions

{
  "compilerOptions": {
    ...
    "lib": [
      "dom"
    ]
  }
}

or declare the object as any export function removeRouteParams() {(window.history as any).replaceState({}, document.title, '/');}

potapovnikita commented 5 years ago

@darklightcode, "dom" is already added. Declare the object does not solve this problem.

I'm think that is a bug of typescript 3.2, because in version 3.1.6. all good.

agg23 commented 5 years ago

Also can replicate running on Typescript 3.2.2, whereas it works fine on 3.1.6.

astorije commented 5 years ago

Most likely duplicate of #618

ajaska commented 5 years ago

For anyone else coming in via Google, had this (It gave the same top level "Buffer or String" error as #618 which may be related, but I confirmed that my issue was around history).

This issue is related to TypeScript itself crashing because of https://github.com/Microsoft/TypeScript/issues/28810

For anyone looking for a temporary fix, I'd recommend

(window.history as any).replaceState

Or, if you're like me, and you can't cast to any because you're calling window.history from a Javascript file (and somehow that's crashing TypeScript 🤔), you can be disgusting (like me) and do:

/**
  * put a big comment here about the TypeScript + window.history issue,
  * so other people will judge you less
  */
window["h"+"istory"].replaceState
delesseps commented 5 years ago

I had similar issues but some of the workarounds above didn't work for me so I used the following

(window as any).history