Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Webpack can't handle worker files when running tests #135

Closed
kappaj opened this issue Mar 9, 2018 · 1 comment
Closed

Webpack can't handle worker files when running tests #135

kappaj opened this issue Mar 9, 2018 · 1 comment

Comments

@kappaj
Copy link

kappaj commented Mar 9, 2018

Im trying to setup an Angular project with Worker Loader. I am able to run the app but failed at running karma! Here is my approach:

  1. Created project with ng new webpack-worker-loader-karma -> ng serve and ng test works

  2. Added webpack worker-loader to project npm i -D worker-loader

  3. Created worker typescript file src/app/simple-loader.ts

  4. Created worker type definitions in src/typings.d.ts:

     declare module 'worker-loader?inline!*' {
       class WebpackWorker extends Worker {
       constructor();
     }
    
     export default WebpackWorker;
     }
    
  5. Added code for instantiation of worker in src/app/app.component.ts -> ng serve returns this error:

     ERROR in ./node_modules/@ngtools/webpack/src!./src/app/simple-worker.ts
     Module build failed: Error: @ngtools/webpack is being used as a loader but no `tsConfigPath` option nor AotPlugin was detected. You must provide at least one of these.
         at Object.ngcLoader (/[path]/webpack-worker-loader-karma/node_modules/@ngtools/webpack/src/loader.js:617:19)
    

`

  1. Had to set the tsConfigPath in webpack.config.js. So I ejected the project and changed the config:

     {
         "test": /\.ts$/,
         "loader": "@ngtools/webpack",
         "options": {
           "tsConfigPath": "src/tsconfig.app.json",
         }
     }
    

npm start -> works!

npm test -> error:

ERROR in ./node_modules/@ngtools/webpack/src!./src/app/simple-worker.ts
    Module build failed: Error: @ngtools/webpack is being used as a loader but no `tsConfigPath` option nor AotPlugin was detected. You must provide at least one of these.
        at Object.ngcLoader (/[path]/webpack-worker-loader-karma/node_modules/@ngtools/webpack/src/loader.js:617:19)

I think I have to set the tsConfigPath for karma or set the worker loader correctly. But don't know how. Any ideas?

I published the project on github:

https://github.com/kappaj/webpack-worker-loader-karma

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants