Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__webpack_require__.hmd is not a function #2651

Closed
provegard opened this issue Mar 6, 2021 · 4 comments
Closed

__webpack_require__.hmd is not a function #2651

provegard opened this issue Mar 6, 2021 · 4 comments

Comments

@provegard
Copy link

Issue description or question

I have a project that contains Vue SFC files. These are processed by Webpack's vue-loader. When I try to use Wallaby instead of Karma+karma-webpack, I get:

Runtime error: TypeError: __webpack_require__.hmd is not a function
    at Module.window.__moduleBundler.modules.<computed> (http://localhost:61620/____wallaby-bundle.js?1615072519557&wallabyFileId=bundle:27:53)
    at window.__moduleBundler.require (http://localhost:61620/____wallaby-webpack.js?1615072519550:24:16)
    at Module.window.__moduleBundler.modules.<computed> (http://localhost:61620/____wallaby-bundle.js?1615072519557&wallabyFileId=bundle:5:72)
    at window.__moduleBundler.require (http://localhost:61620/____wallaby-webpack.js?1615072519550:24:16)
    at Module.window.__moduleBundler.modules.<computed> (http://localhost:61620/test/personSpec.js.wbp.js?1615072519455&wallabyFileId=2:2:69)
    at Object.window.__moduleBundler.require (http://localhost:61620/____wallaby-webpack.js?1615072519550:24:16)
    at http://localhost:61620/____wallaby-webpack-bootstrapper.js?1615072519551:18:36
    at http://localhost:61620/__wallaby__/tracer.js:15:12377
    at u._doWhenReceiverIsReady (http://localhost:61620/__wallaby__/tracer.js:14:10272)
    at Object._startWhenReceiverIsReady (http://localhost:61620/__wallaby__/tracer.js:15:12343)
    at Object.window.__moduleBundler.loadTests (http://localhost:61620/____wallaby-webpack-bootstrapper.js?1615072519551:13:22)
    at http://localhost:61620/wallaby_sandbox0.html:11:30
    at http://localhost:61620/wallaby_sandbox0.html:12:7

To reproduce, run Wallaby from /~https://github.com/provegard/wallaby-webpack-sample/tree/vue-hmd. Please note that the repro is on the vue-hmd branch.

Wallaby diagnostics report

{
  editorVersion: 'IntelliJ IDEA 2020.3.2',
  pluginVersion: '1.0.213',
  editorType: 'IntelliJ',
  osVersion: 'win32 10.0.19042',
  nodeVersion: 'v14.16.0',
  coreVersion: '1.0.1042',
  config: {
    files: [
      { pattern: 'node_modules/chai/chai.js', instrument: false, ignore: false, trigger: true, load: true, order: 1 },
      { pattern: 'src/**/*.js', load: false, ignore: false, trigger: true, order: 2 },
      { pattern: 'src/**/*.vue', load: false, ignore: false, trigger: true, order: 3 }
    ],
    tests: [ { pattern: 'test/**/*Spec.js', load: false, ignore: false, trigger: true, test: true, order: 4 } ],
    trace: true,
    diagnostics: {},
    filesWithNoCoverageCalculated: [],
    runAllTestsInAffectedTestFile: false,
    updateNoMoreThanOneSnapshotPerTestFileRun: false,
    addModifiedTestFileToExclusiveTestRun: true,
    compilers: {},
    preprocessors: {},
    maxConsoleMessagesPerTest: 100,
    autoConsoleLog: true,
    delays: { run: 0, edit: 100, update: 0 },
    workers: { initial: 0, regular: 0, recycle: false },
    teardown: undefined,
    hints: {
      ignoreCoverage: '__REGEXP /ignore coverage|istanbul ignore/',
      ignoreCoverageForFile: '__REGEXP /ignore file coverage/',
      commentAutoLog: '?',
      testFileSelection: { include: '__REGEXP /file\\.only/', exclude: '__REGEXP /file\\.skip/' }
    },
    automaticTestFileSelection: true,
    runSelectedTestsOnly: false,
    extensions: {},
    env: { type: 'browser', kind: 'chrome', params: {}, viewportSize: { width: 800, height: 600 }, options: { width: 800, height: 600 }, bundle: true },
    reportUnhandledPromises: false,
    throwOnBeforeUnload: true,
    testFramework: { version: 'jasmine@3.6.0', configurator: 'jasmine@2.1.3', reporter: 'jasmine@2.1.3', starter: 'jasmine@2.1.3' },
    slowTestThreshold: 75,
    lowCoverageThreshold: 80,
    loose: true,
    configCode: 'const { VueLoaderPlugin } = require("vue-loader")\r\n' +
      '\r\n' +
      'module.exports = function (wallaby) {\r\n' +
      '\r\n' +
      '  return {\r\n' +
      '    files: [\r\n' +
      '      // loading chai globally\r\n' +
      "      { pattern: 'node_modules/chai/chai.js', instrument: false },\r\n" +
      "      { pattern: 'src/**/*.js', load: false },\r\n" +
      "      { pattern: 'src/**/*.vue', load: false }\r\n" +
      '    ],\r\n' +
      '\r\n' +
      '    tests: [\r\n' +
      "      { pattern: 'test/**/*Spec.js', load: false }\r\n" +
      '    ],\r\n' +
      '\r\n' +
      '    // compilers: {\r\n' +
      "    //   '**/*.js': wallaby.compilers.babel()\r\n" +
      '    // },\r\n' +
      '\r\n' +
      '    postprocessor: wallaby.postprocessors.webpack({\r\n' +
      '      resolve: {\r\n' +
      '        extensions: [".js", ".vue"]\r\n' +
      '      },\r\n' +
      '      plugins: [new VueLoaderPlugin()],\r\n' +
      '      module: {\r\n' +
      '        rules: [\r\n' +
      '          {\r\n' +
      '            test: /\\.vue$/,\r\n' +
      '            loader: "vue-loader"\r\n' +
      '          }\r\n' +
      '        ]\r\n' +
      '      }\r\n' +
      '    }),\r\n' +
      '\r\n' +
      '    setup: function () {\r\n' +
      '      window.expect = chai.expect;\r\n' +
      '      window.__moduleBundler.loadTests();\r\n' +
      '    },\r\n' +
      '\r\n' +
      '    trace: true,\r\n' +
      '  };\r\n' +
      '};\r\n'
  },
  packageJSON: {
    dependencies: { vue: '^2.6.12', 'vue-template-compiler': '^2.6.12' },
    devDependencies: { 'babel-core': '^6.26.0', 'babel-preset-es2015': '^6.24.1', chai: '^4.1.2', 'vue-loader': '^15.9.6', 'wallaby-webpack': '^3.9.4', webpack: '^5.24.3' }
  },
  fs: { numberOfFiles: 4 },
  debug: [
    '2021-03-06T23:18:22.096Z project Wallaby Node version: v14.16.0\n',
    '2021-03-06T23:18:22.096Z project Wallaby config: C:\\kod\\projects\\wallaby-webpack-sample\\wallaby.js\n',
    '2021-03-06T23:18:22.165Z project File cache: C:\\Users\\perro\\AppData\\Local\\JetBrains\\IntelliJIdea2020.3\\wallaby\\projects\\66782bc09218eff1\n',
    '2021-03-06T23:18:22.380Z uiService Listening port 51235\n',
    '2021-03-06T23:18:22.479Z workers Parallelism for initial run: 6, for regular run: 3\n',
    '2021-03-06T23:18:22.479Z workers Starting run worker instance #0\n',
    '2021-03-06T23:18:22.479Z workers Starting run worker instance #1\n',
    '2021-03-06T23:18:22.479Z workers Starting run worker instance #2\n',
    '2021-03-06T23:18:22.479Z workers Starting run worker instance #3\n',
    '2021-03-06T23:18:22.479Z workers Starting run worker instance #4\n',
    '2021-03-06T23:18:22.479Z workers Starting run worker instance #5\n',
    '2021-03-06T23:18:22.482Z workers Web server is listening at 61667\n',
    '2021-03-06T23:18:22.490Z project Stopping process pool\n',
    '2021-03-06T23:18:22.490Z project File cache is up-to-date, starting full test run\n',
    '2021-03-06T23:18:22.502Z project Running postprocessor\n',
    '2021-03-06T23:18:22.506Z postprocessor Processing started.\n',
    '2021-03-06T23:18:22.506Z postprocessor Initializing.\n',
    '2021-03-06T23:18:22.506Z postprocessor Initializing entry.\n',
    '2021-03-06T23:18:22.506Z postprocessor Sanitizing configuration.\n',
    '2021-03-06T23:18:22.507Z postprocessor Adjusting configuration.\n',
    '2021-03-06T23:18:22.507Z postprocessor Creating compiler.\n',
    '2021-03-06T23:18:23.171Z postprocessor Customizing compiler.\n',
    '2021-03-06T23:18:23.171Z postprocessor Compilation started.\n',
    '2021-03-06T23:18:23.548Z postprocessor Compilation finished.\n',
    '2021-03-06T23:18:23.651Z postprocessor Emitting 10 files.\n',
    '2021-03-06T23:18:23.653Z postprocessor Processing finished.\n',
    '2021-03-06T23:18:23.656Z project Postprocessor execution finished\n',
    '2021-03-06T23:18:23.656Z project Test run started; run priority: 3\n',
    '2021-03-06T23:18:23.657Z project Running all tests\n',
    '2021-03-06T23:18:23.658Z workers Starting test run, priority: 3\n',
    '2021-03-06T23:18:23.659Z chromeRunner Starting sandbox [worker #0, session #5snpo]\n',
    '2021-03-06T23:18:23.699Z workers Started run worker instance (immediate) #0\n',
    '2021-03-06T23:18:23.700Z workers Started run worker instance (immediate) #1\n',
    '2021-03-06T23:18:23.700Z workers Started run worker instance (immediate) #2\n',
    '2021-03-06T23:18:23.700Z workers Started run worker instance (immediate) #3\n',
    '2021-03-06T23:18:23.700Z workers Started run worker instance (immediate) #4\n',
    '2021-03-06T23:18:23.700Z workers Started run worker instance (immediate) #5\n',
    '2021-03-06T23:18:23.701Z chromeRunner Preparing sandbox [worker #0, session #5snpo]\n',
    '2021-03-06T23:18:23.702Z browserRunner Total files to load in sandbox: 5\n',
    '2021-03-06T23:18:23.704Z browserRunner Sandbox is generated [worker #0, session #5snpo]: http://localhost:61667/wallaby_sandbox0.html\n',
    '2021-03-06T23:18:23.704Z chromeRunner Prepared sandbox [worker #0, session #5snpo]\n',
    '2021-03-06T23:18:23.705Z workers [worker #0, session #5snpo] Running tests in sandbox\n',
    '2021-03-06T23:18:23.878Z workers Sandbox (active) [5snpo] error: Uncaught TypeError: __webpack_require__.hmd is not a function\n',
    '2021-03-06T23:18:23.880Z workers Failed to map the stack to user code, entry message: Uncaught TypeError: __webpack_require__.hmd is not a function, stack: TypeError: __webpack_require__.hmd is not a function\n' +
      '    at Module.window.__moduleBundler.modules.<computed> (http://localhost:61667/____wallaby-bundle.js?1615072703654&wallabyFileId=bundle:27:53)\n' +
      '    at window.__moduleBundler.require (http://localhost:61667/____wallaby-webpack.js?1615072703650:24:16)\n' +
      '    at Module.window.__moduleBundler.modules.<computed> (http://localhost:61667/____wallaby-bundle.js?1615072703654&wallabyFileId=bundle:5:72)\n' +
      '    at window.__moduleBundler.require (http://localhost:61667/____wallaby-webpack.js?1615072703650:24:16)\n' +
      '    at Module.window.__moduleBundler.modules.<computed> (http://localhost:61667/test/personSpec.js.wbp.js?1615072703554&wallabyFileId=2:2:69)\n' +
      '    at Object.window.__moduleBundler.require (http://localhost:61667/____wallaby-webpack.js?1615072703650:24:16)\n' +
      '    at http://localhost:61667/____wallaby-webpack-bootstrapper.js?1615072703650:18:36\n' +
      '    at http://localhost:61667/__wallaby__/tracer.js:15:12377\n' +
      '    at u._doWhenReceiverIsReady (http://localhost:61667/__wallaby__/tr\n',
    '2021-03-06T23:18:23.885Z workers [5snpo] Loaded 0 test(s)\n',
    '2021-03-06T23:18:23.892Z workers [5snpo] Run 0 test(s), skipped 0 test(s)\n',
    '2021-03-06T23:18:23.894Z workers [5snpo] Sandbox is responsive, closing it\n',
    '2021-03-06T23:18:23.896Z project Test run finished\n',
    '2021-03-06T23:18:23.896Z project Processed console.log entries\n',
    '2021-03-06T23:18:23.896Z project Processed loading sequences\n',
    '2021-03-06T23:18:23.896Z project Processed executed tests\n',
    '2021-03-06T23:18:23.897Z project Processed code coverage\n',
    '2021-03-06T23:18:23.907Z project Test run result processed and sent to IDE\n'
  ]
}
@smcenlly
Copy link
Member

smcenlly commented Mar 7, 2021

It looks like your sample repo is our base webpack sample with some added dependencies but is missing vue configuration and vue webpack configuration.

I am going to assume that you are using a Vue CLI 4.x project, in which case the configuration below (from our docs) should work for you:

Wallaby.js

const config = require("@vue/cli-service/webpack.config.js");

const redundantPlugins = {
  ForkTsCheckerWebpackPlugin: true,
  PreloadPlugin: true,
  HtmlWebpackPlugin: true,
  CopyPlugin: true,
  CaseSensitivePathsPlugin: true,
  FriendlyErrorsWebpackPlugin: true,
};

config.plugins = config.plugins.filter(
  (plugin) => !(plugin.constructor && redundantPlugins[plugin.constructor.name])
);

// vue files are split into multiple webpack modules,
// we need to choose and map script webpack resource (i.e. module) to one absolute file path
const mapResourceToPath = (context) => {
  const resource = context.resource;

  if (!resource) return resource;

  if (context.version) {
    // loading phase
    if (resource.endsWith("vue")) {
      return `${resource}?ignore`;
    }

    return resource.indexOf("type=script") > 0
      ? context.resourcePath
      : resource;
  }

  // processing phase
  return resource.indexOf("type=script") > 0 && context.wallaby
    ? resource.substring(0, resource.indexOf("?"))
    : resource.endsWith("vue")
    ? `${resource}?ignore`
    : resource;
};

module.exports = function(wallaby) {
  return {
    files: [
      { pattern: "src/**/*.*", load: false },
      { pattern: "tests/**/*.*", load: false },
      { pattern: "tests/**/*.spec.*", load: false, ignore: true }
    ],

    tests: [
      { pattern: "tests/**/*.*", load: false },
      { pattern: "tests/**/*.spec.*", load: false }
    ],

    postprocessor: wallaby.postprocessors.webpack(config, {
      setupFiles: [require.resolve("@vue/cli-plugin-unit-mocha/setup")],
      mapResourceToPath: mapResourceToPath,
    }),

    env: {
      kind: "chrome",
    },

    setup: function() {
      // required to trigger test loading
      window.__moduleBundler.loadTests();
    },
  };
};

If you're still having problems, would you mind updating the sample repo so that your vue code runs tests outside of Wallaby, or else provide us with a different sample repo?

@provegard
Copy link
Author

Hi! I'm not familiar with Vue CLI. In the real repo where I encountered this problem, we're just using Vue as an imported module and it works with Karma and karma-webpack, but not with Wallaby.

I'll try the suggested configuration and will let you know how it works.

@smcenlly
Copy link
Member

smcenlly commented Mar 8, 2021

If it doesn't work for you, would you be able to duplicate your configuration so that we can see your karma tests running outside of wallaby (including your karma-webpack config)?

@provegard
Copy link
Author

Thank you, the proposed solution got rid of the hmd problem. This opened up for other problems, some of which Wallay was helpful in diagnosing, others which are more mysterious. I'll open separate issues for the ones I'm not able to figure out.

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

No branches or pull requests

2 participants