developit/workerize-loader

Typescript Cannot find name '__webpack_public_path__'

leonidkuznetsov18 opened this issue · 1 comments

component.tsx

import * as DiffWorker from "../../workers/Diff.worker";

Diff.worker.ts

import * as DiffMatchPatch from "diff-match-patch";
const Changeset = require("changesets").Changeset;

const dmp = new DiffMatchPatch();

export function diffCalc(a, b) {
  console.log("a", typeof a, "b", typeof b);
  const diff = dmp.diff_main(a, b);
  // @ts-ignore
  const changeSetPack = Changeset.fromDiff(diff).pack();
  return changeSetPack;
}

tsconfig.json

  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "allowJs": true,
    "forceConsistentCasingInFileNames": true,
    "lib": [
      "esnext",
      "webworker",
      "dom"
    ],
    "module": "commonjs",
    "target": "es5",
    "moduleResolution": "node",
    "outDir": "build",
    "rootDir": "/",
    "sourceMap": true,
    "strictNullChecks": false,
    "noImplicitReturns": false,
    "noImplicitThis": false,
    "noImplicitAny": false,
    "jsx": "react",
    "suppressImplicitAnyIndexErrors": false
  },
  "exclude": [
    "node_modules",
    "build"
  ],
}

webpack.config

      {
        test: /\.(ts|tsx)$/,
        use: ['awesome-typescript-loader'],
        exclude: path.resolve(__dirname, 'node_modules'),
      },
      {
        test: /\.worker\.ts$/,
        use: ['workerize-loader'],
        exclude: path.resolve(__dirname, 'node_modules'),
      }

output error

 「atl」: Checking finished with 1 errors
[at-loader] ./src/client/workers/Diff.worker.ts:5:25
    TS2304: Cannot find name '__webpack_public_path__'.

SOLUTIONS
this help me

Add enforce:'pre' to awesome-ts-loader, or reverse the order of the two module rules.