codedbypaul
codedbypaul

Reputation: 13

Aurelia: Error: Unable to find module with ID: aurelia-pal-browser in Karma test with Webpack

I'm having an issue creating a test for an Aurelia component. In Karma debug the console shows:

Error: Unable to find module with ID: aurelia-pal-browser from aurelia-loader-webpack.

I'm using Webpack 4 and Karma 2.

I've tried the suggestions in Debugging missing modules but haven't any luck.

Anyone else come across this before?

Karma config

module.exports = function(config) {
  config.set({
    basePath: '',frameworks: ['jasmine'],
    files: [
      './setup.js',
      '../src/**/*.js',
      './unit/**/*.js'
    ],
    exclude: [],
    preprocessors: {
      './setup.js': ['webpack'],
      '../src/**/*.js': ['webpack', 'coverage'],
      './unit/**/*.js': ['webpack']
    },
    reporters: ['progress', 'coverage'],
    webpack: {
      mode: 'development',
      module: {
        rules: [{
          test: /\.js$/,
          exclude: /node_modules/,
          use: {
            loader: 'babel-loader'
          }
        }]
      }
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

Aurelia test

import { StageComponent } from 'aurelia-testing';
import { bootstrap } from 'aurelia-bootstrapper';
import { PLATFORM } from 'aurelia-pal';

export class TestViewModel {
}

describe('cbs-toast tests', () => {
  let component;
  let viewModel;

  beforeEach(() => {
    viewModel = new TestViewModel();
    component = StageComponent
      .withResources(PLATFORM.moduleName('cbs-toast'))
      .inView('<div><toast></toast></div>')
      .boundTo(viewModel);
  });

  it('loads ok', done => {
    component.create(bootstrap).then(() => {
      done();
    }).catch(e => {
      console.log(e.toString());
    });
  });

  afterEach(() => {
    component.dispose();
  });
});

Upvotes: 0

Views: 612

Answers (1)

Amitha Mahesh
Amitha Mahesh

Reputation: 347

yes, most of the time if aurelia giving an error saying that "Unable to find module with ID", that's happening because of not using PLATFORM.moduleName() when we call a module. try to search the module name "aurelia-pal-browser" in your project and wrap it like below. PLATFORM.moduleName('aurelia-pal-browser')

Upvotes: 2

Related Questions