Error during "yarn pack": Cannot find module "."
Do you want to request a feature or report a bug? 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 Generator.next (<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
I tracked that piece of code to this https://github.com/stefanpenner/hash-for-dep/blob/master/lib/pkg.js . It looks like webpack tries to resolve that require statement and that is not right.
I'd personnally advise you not to use bundled dependencies, ever, whether it's on Yarn or any other package manager. They are a badly designed feature 😕
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.
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 :sweat_smile:
And if you fix the broken webpack require, yarn will pack the package without including any bundledDependencies
@payload Would you be able to share your custom solution?
@GusGold unfortunately not. It's actually fun to write such a bundle script, but you could also just fairly straight forward write a script which does all the manual steps hardcoded. npm pack relevant dependencies, create a zip archive, put all the files and dependencies as tgz in, rewrite package.json dependencies to use those tgz.
No worries, @payload . I started writing a very similar solution last night, but was trying to emulate yarn's cache and then using yarn install --cache-folder [custom-packed-modules] but wasn't able to consistantly trick yarn into using them.
I hadn't considered rewriting the package.json to look directly for the tgz, thanks!
Since it's impossible to test this now that yarn pack is broken, please also make sure to pack any symlinked bundledDependencies first before bundling. npm link messed this up, it caused the "files" field in manifest or an .npmignore file to be ignored and the entire symlink source folder to be bundled. I hope yarn will not repeat this mistake.
Not sure if this particular issue is fixable at all, but ran into it setting up some simple testing to (hopefully) contribute a fix for #5998.
With yarn v1 sticking around as the "npm compatible" option compared to yarn v2 / "berry", maybe we can start fixing up some of these bundledDependencies issues, even though they aren't the most popular :) Going to see if I can actually do something with #5998 first...
Closing as we've completely removed support for bundleDependencies in v2, for the reasons stated here https://yarnpkg.com/getting-started/migration#dont-use-bundledependencies. We aren't going to spend more time fixing them in v1.