0

I added Gulp.js v4 to the project's dependencies and ran yarn install --no-bin-links to install locally.

$ yarn install --no-bin-links
yarn install v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.12: The platform "linux" is incompatible with this module.
info "fsevents@1.2.12" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...

success Saved lockfile.
Done in 32.48s.

(I'm using the --no-bin-links parameter to avoid this error: error An unexpected error occurred: "EPROTO: protocol error, symlink '../../../semver/bin/semver' -> '/path/to/project/public/components/accord/node_modules/.bin/semver'".)

The package.json defines the correct version ranges:

{
  ...
  "dependencies": {
    "bootstrap": "^3.3.6",
    "gulp": "^4.0.2",
    "gulp-autoprefixer": "*",
    "gulp-cli": "^2.2.0",
    "gulp-filter": ">=6.0.0",
    "gulp-less": "*",
    "gulp-plumber": "*",
    "gulp-rename": "*",
    "gulp-watch": "*",
    "html5shiv": ">=3.7.3",
    "jquery": "^3.4.0",
    "jquery-ui": "^1.12.1",
    "jquery-ui-dist": "^1.12.1",
    "path": "*",
    "respond": ">=0.9.0"
  },
  ...
}

The yarn.lock also refers the correct version:

...
gulp@^4.0.2:
  version "4.0.2"
...
gulp-cli@>=2.2.0, gulp-cli@^2.2.0:
  version "2.2.0"
...

And also the yarn list provides the expected output:

$ yarn list | grep "gulp"
├─ gulp-autoprefixer@7.0.1
├─ gulp-cli@2.2.0
│  ├─ gulplog@^1.0.0
├─ gulp-filter@6.0.0
├─ gulp-less@4.0.1
├─ gulp-plumber@1.2.1
├─ gulp-rename@2.0.0
├─ gulp-watch@5.0.1
├─ gulp@4.0.2
│  ├─ gulp-cli@^2.2.0
├─ gulplog@1.0.0

But when I now execute gulp, old versions (Gulp 3.9.1 and Gulp CLI 1.2.1 are used:

$ ./public/components/gulp/bin/gulp.js -v
[15:42:30] CLI version 1.2.1
[15:42:30] Local version 3.9.1

What is wrong here and how to install the required Gulp version locally correctly with Yarn and make this version be used?

Cameron Little
  • 3,487
  • 23
  • 35
automatix
  • 14,018
  • 26
  • 105
  • 230
  • This is related - https://stackoverflow.com/questions/9679932/how-to-use-executables-from-a-package-installed-locally-in-node-modules – Cameron Little Apr 19 '20 at 09:46

1 Answers1

1

Unless your PATH has been customized, running gulp on the CLI will always reference the global version if installed.

You need to reference the one installed locally. If you install normally (without --no-bin-links) you can use any of these techniques.

  1. Create a yarn script such as "foo": "gulp --version". This will reference the local version of gulp.

  2. Use yarn gulp

  3. Use $(yarn bin)/gulp

Using --no-bin-links, you can directly reference the binary, it's just harder because it hasn't been linked to its standard location.

First, you need to find metadata about the binaries associated with gulp (actually, gulp-cli), which you can do with yarn info: yarn info gulp-cli bin. Then, you need execute that binary.

node ./node_modules/gulp-cli/bin/gulp.js --version

The problem with this is it's not safe if the internal organization of gulp changes, so getting the binary linked is a better approach.

You can make it somewhat safer by generating the command with subprocesses, but you still depend on the structure of node_modules.

Cameron Little
  • 3,487
  • 23
  • 35