yarn icon indicating copy to clipboard operation
yarn copied to clipboard

yarn install fails when using modules-folder flag

Open alexrs opened this issue 5 years ago • 7 comments

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

What is the current behavior? yarn install --modules-folder another_modules fails with

$ /usr/local/bin/yarn install --modules-folder another_modules

error another_modules/realm: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments:
Directory: another_modules/realm
Output:
internal/modules/cjs/loader.js:582
    throw err;
    ^

Error: Cannot find module 'nopt'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (PATH/another_modules/node-pre-gyp/lib/node-pre-gyp.js:15:12)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)

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

Steps to reproduce:

  1. Remove node_modules
  2. yarn cache clean
  3. yarn install --modules-folder another_modules

This error might be specific to Realm. Running yarn install or yarn install --modules-folder node_modules works as expected.

What is the expected behavior? The modules are successfully installed, as when running yarn install, but in the folder specified in --modules-folder instead of in node_modules.

Please mention your node.js, yarn and operating system version. node v10.14.1, yarn 1.17.3, macOS 10.14.5

alexrs avatar Aug 08 '19 20:08 alexrs

I also failed to install package when modules-folder was specified Might be the same issue

$ yarn add coffeescript --modules-folder x --ignore-scripts
yarn add v1.17.3
warning package.json: No license field
info No lockfile found.
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
warning Ignored scripts due to flag.
success Saved lockfile.
warning No license field
success Saved 127 new dependencies.
info Direct dependencies
├─ [email protected]
└─ [email protected]
info All dependencies
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
Done in 1.29s.

$ yarn add babel --modules-folder x --ignore-scripts
yarn add v1.17.3
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
warning [email protected]: In 6.x, the babel package has been deprecated in favor of babel-cli. Check https://opencollective.com/babel to support the Babel maintainers
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
error An unexpected error occurred: "ENOENT: no such file or directory, lstat '/tmp/bug/x/babylon'".
info If you think this is a bug, please open a bug report with the information provided in "/tmp/bug/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

allenwu1973 avatar Aug 28 '19 12:08 allenwu1973

Same here. Without --modules-folder everything works fine.

Error message: Exit code: 1 Command: opencollective-postinstall || true Arguments: Directory: public_html\libraries\flag-icon-css Output: 'opencollective-postinstall' is not recognized as an internal or external command, operable program or batch file. 'true' is not recognized as an internal or external command, operable program or batch file.

Full script: $ yarn install --modules-folder "./public_html/libraries" --ignore-optional --production=true [1/5] Resolving packages... [2/5] Fetching packages... [3/5] Linking dependencies... warning " > [email protected]" has incorrect peer dependency "leaflet@~1.3.1". [4/5] Building fresh packages... [1/2] ⠂ core-js error public_html\libraries\flag-icon-css: Command failed. Exit code: 1 Command: opencollective-postinstall || true Arguments: Directory: public_html\libraries\flag-icon-css Output: 'opencollective-postinstall' is not recognized as an internal or external command, operable program or batch file. 'true' is not recognized as an internal or external command, operable program or batch file.

poradz avatar Oct 03 '19 11:10 poradz

same here: yarn --modules-folder ../some_folder

error ../some_folder/gifsicle: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments: 
Directory: ../some_dumb_folder/gifsicle
Output:
module.js:550
    throw err;
    ^

Error: Cannot find module 'bin-build'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/some_dumb_folder/gifsicle/lib/install.js:2:16)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)

dastanko avatar Oct 08 '19 07:10 dastanko

I've figured out, that after removing modules folder with partially downloaded libraries and run yarn install again error doesn't appear. It shouldn't work like that, but apparently removing destination folder before yarn install with --modules-folder flag solves many problems.

poradz avatar Oct 17 '19 07:10 poradz

In my case (installing bcrypt), I had to manually change PATH, so that node-pre-gyp could be found. The error didn't stop by removing the modules folder, as suggested above, or changing NODE_PATH, as suggested in this grpc issue.

Steps to reproduce problem:

yarn init -y
yarn add bcrypt
yarn install --modules-folder somewhere
Output:
/bin/sh: 1: node-pre-gyp: not found

The fix (without resorting to installing node-pre-gyp globally):

PATH="node_modules/.bin" yarn install --modules-folder somewhere

humodz avatar Apr 09 '21 13:04 humodz

I've figured out, that after removing modules folder with partially downloaded libraries and run yarn install again error doesn't appear

Never, in my entire life, removing node_modules was a solution, and... Aw shit, here we go again!

Jokes aside, it seems, it kinda worked because the behavior changed a little, yarn install now completes, but...

✔️ I have a postinstall script in my package.json, and without modules folder, it works nicely:

$ yarn install
...
$ electron-builder install-app-deps
  • electron-builder  version=22.13.1
  • loaded configuration  file=C:\Users\Jerry\MyProject\electron-builder.yml
Done in 5.53s.

❌ But when I use custom modules-folder, though yarn install completes, this postinstall script cannot be called:

$ yarn install
...
$ electron-builder install-app-deps
'electron-builder' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.

However, changing the script from this:

"postinstall": "electron-builder install-app-deps",

To this:

"postinstall": "yarn electron-builder install-app-deps",

Resolved this case, but I still have to add "yarn" into every other script: start, dev, build, etc etc. It wasn't needed earlier, and depending on either I run yarn or npm, it used the corresponding package manager, depending on which one was called initially. Now I have to add "yarn" literally everywhere.

jerrygreen avatar Oct 10 '21 02:10 jerrygreen

Had same issue. Found a simple solution. Make sure the last folder name from your custom modules-folder is node_modules. Example:

yarn install --modules-folder /your/custom/path/node_modules

In my use case I wanted to install dependencies on the server in a custom folder (in npm root) during the deployment pipeline. So i've configured my deploy scrip to contain:

# Create the new path as a var.
export APP_CUSTOM_MODULES_FOLDER="$(npm root -g)/my_app/node_modules"

# Execute install
nodeProcess=$(yarn install --modules-folder $APP_CUSTOM_MODULES_FOLDER 2>&1)
echo "$nodeProcess"

# Create a symlink in the app root (where pacakge.json is) to our custom path.
ln -s $APP_CUSTOM_MODULES_FOLDER node_modules

Hope it helps someone in the future.

nicolaelitvac avatar May 27 '22 11:05 nicolaelitvac