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

Uncaught (in promise) Error: Could not find module ../@ember/test-helpers/index.js imported from (require) #1078

Closed
thoov opened this issue Jan 13, 2022 · 4 comments

Comments

@thoov
Copy link
Collaborator

thoov commented Jan 13, 2022

Starting in v0.49.0+ I am seeing this error (v0.47.0 & v0.48.0 worked fine):

Uncaught (in promise) Error: Could not find module `../@ember/test-helpers/index.js` imported from `(require)`
    at missingModule (vendor.js:254:11)
    at findModule (vendor.js:265:7)
    at requireModule (vendor.js:31:15)
    at Module.callback (chunk.d52098f8114ab94f4e23.js:171157:67)
    at Module.exports (vendor.js:113:32)
    at requireModule (vendor.js:34:18)
    at getRfc232TestContext (chunk.d52098f8114ab94f4e23.js:171171:66)
    at _shouldUseMirage (chunk.c965491da35091374282.js:208433:102)
    at Object.initialize (chunk.c965491da35091374282.js:208413:9)
    at vendor.js:37224:21

getRfc232TestContext module looks like:

/***/ "./node_modules/ember-cli-mirage/get-rfc232-test-context.js":
/*!******************************************************************!*\
  !*** ./node_modules/ember-cli-mirage/get-rfc232-test-context.js ***!
  \******************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ getRfc232TestContext)
/* harmony export */ });
/* harmony import */ var _externals_require__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../externals/require */ "../externals/require.js");
/* harmony import */ var _externals_require__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_externals_require__WEBPACK_IMPORTED_MODULE_0__);
window.define("@ember/test-helpers", function () {
  return _externals_require__WEBPACK_IMPORTED_MODULE_0___default()("../@ember/test-helpers/index.js");
});
 //
// Helper to get our rfc232/rfc268 test context object, or null if we're not in
// such a test.
//

function getRfc232TestContext() {
  // Support older versions of `ember-qunit` that don't have
  // `@ember/test-helpers` (and therefore cannot possibly be running an
  // rfc232/rfc268 test).
  if (_externals_require__WEBPACK_IMPORTED_MODULE_0___default().has('@ember/test-helpers')) {
    let {
      getContext
    } = _externals_require__WEBPACK_IMPORTED_MODULE_0___default()('@ember/test-helpers');

    return getContext();
  }
}

Specifically these lines cause problems:

window.define("@ember/test-helpers", function () {
  return _externals_require__WEBPACK_IMPORTED_MODULE_0___default()("../@ember/test-helpers/index.js");
});

I am also seeing this happen in other modules as well where it is creating ../module-name/index.js and throwing an error.

In v0.48.0 this is what the module looked like:

/***/ "./node_modules/ember-cli-mirage/get-rfc232-test-context.js":
/*!******************************************************************!*\
  !*** ./node_modules/ember-cli-mirage/get-rfc232-test-context.js ***!
  \******************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ getRfc232TestContext)
/* harmony export */ });
/* harmony import */ var _ember_test_helpers_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../@ember/test-helpers/index.js */ "./node_modules/@ember/test-helpers/index.js");
/* harmony import */ var _externals_require__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../externals/require */ "../externals/require.js");
/* harmony import */ var _externals_require__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_externals_require__WEBPACK_IMPORTED_MODULE_1__);

window.define("@ember/test-helpers", function () {
  return _ember_test_helpers_index_js__WEBPACK_IMPORTED_MODULE_0__;
});
 //
// Helper to get our rfc232/rfc268 test context object, or null if we're not in
// such a test.
//

function getRfc232TestContext() {
  // Support older versions of `ember-qunit` that don't have
  // `@ember/test-helpers` (and therefore cannot possibly be running an
  // rfc232/rfc268 test).
  if (_externals_require__WEBPACK_IMPORTED_MODULE_1___default().has('@ember/test-helpers')) {
    let {
      getContext
    } = _externals_require__WEBPACK_IMPORTED_MODULE_1___default()('@ember/test-helpers');

    return getContext();
  }
}

/***/ }),
@ef4
Copy link
Contributor

ef4 commented Jan 13, 2022

I just remembered where those window.define are coming from. They're extraImports being added by a packageRule.

And their behavior changed in 0.49.0: #1043

@ef4
Copy link
Contributor

ef4 commented Jan 13, 2022

The part that's likely to be relevant is

function amdDefine(t: BabelTypes, adder: ImportUtil, path: NodePath<t.Program>, target: string, runtimeName: string) {
let value = t.callExpression(adder.import(path, '@embroider/macros', 'importSync'), [t.stringLiteral(target)]);
return t.expressionStatement(
t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [
t.stringLiteral(runtimeName),
t.functionExpression(null, [], t.blockStatement([t.returnStatement(value)])),
])
);
}

Which started inserting an importSync, which will itself get further transformed by the macros-babel-plugin.

Some combination of those two things is what's emitting these weird relative paths.

@thoov
Copy link
Collaborator Author

thoov commented Jan 15, 2022

Steps to reproduce:

  • create new app with embroider
  • ember install [email protected]
  • Add to ember-cli-build.js:
packageRules: [{
  package: 'ember-cli-mirage',
  addonModules: {
    'get-rfc232-test-context.js': { dependsOnModules: ['@ember/test-helpers'] }
  }
}],
  • ember s, you should see the error in the browser's console and the page will not render

ef4 added a commit that referenced this issue Jan 18, 2022
This is a fix for #1078. I plan to add a test too.
@ef4
Copy link
Contributor

ef4 commented Jan 19, 2022

Fixed in #1081

@ef4 ef4 closed this as completed Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants