Error during “yarn pack”: Cannot find module “.”

Do you want to request a feature or report a bug?

What is the current behavior?
Running the command yarn pack throws an error if there are any packages in bundledDependencies

Error: Cannot find module "."
    at webpackMissingModule (/usr/local/Cellar/yarn/1.12.3/libexec/lib/cli.js:109772:64)
    at pkg (/usr/local/Cellar/yarn/1.12.3/libexec/lib/cli.js:109772:142)
    at again (/usr/local/Cellar/yarn/1.12.3/libexec/lib/cli.js:109727:22)
    at depsFor (/usr/local/Cellar/yarn/1.12.3/libexec/lib/cli.js:109741:4)
    at /usr/local/Cellar/yarn/1.12.3/libexec/lib/cli.js:42211:30
    at (<anonymous>)
    at step (/usr/local/Cellar/yarn/1.12.3/libexec/lib/cli.js:304:30)
    at /usr/local/Cellar/yarn/1.12.3/libexec/lib/cli.js:315:13
    at <anonymous>

I tracked the bug to this section of code, more specifically the line with the thePackage assign

/* 725 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var resolvePkg = __webpack_require__(726);

/* @private
 * given the name of a descendent module this module locates and returns its
 * package.json. In addition, it provides the baseDir.
 * @method pkg
 * @param {String} name
 * @param {String} dir (optional) root directory to begin resolution
module.exports = function pkg(name, dir) {
  if (name !== './') { name += '/'; }

  var packagePath = resolvePkg(name, dir);
  if (packagePath === null) { return null; }

  var thePackage = !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }());

  thePackage.baseDir = packagePath.slice(0, packagePath.length - 12 /* index of `/package.json` */);

  return thePackage;

/***/ }),

If the current behavior is a bug, please provide the steps to reproduce.

  • yarn init -y
  • yarn add typescript
  • Add "bundledDependencies": ["typescript"] to the package.json
  • yarn pack

What is the expected behavior?
An archive is created containing the specified module.

Please mention your node.js, yarn and operating system version.
Node 8.12.0
Yarn 1.12.3
MacOS 10.14.1

Author: Fantashit

2 thoughts on “Error during “yarn pack”: Cannot find module “.”

  1. Ok, thanks for the advice.

    I was trying to make a custom piece of code that did exactly this and then I found that yarn had this functionality already built-in. It was sad to find out that it doesn’t work 🙁

    Still, it would be great if this bug gets fixed, because the pack command is kinda useless without the bundledDependencies imho. Or the command should be removed altogether.

  2. I ran into this issue. npm pack bundledDependencies resolution does not work with yarn workspaces hoisted node_modules. yarn pack just fails with this not helpful error message ‘Cannot find module “.”‘.
    I ended up writing my own piece of code to bundle things up. Made mistakes there too 😅

Comments are closed.