Would you use NPM (not Yarn or PNPM) in Sep 2020?
Tags: discuss, node, javascript, yarn
Published: 2020-09-11 20:08:40

AFAIK, NPM has not fixed some serious inconsistencies, namely `scripts.preinstall` and `engineStrict`.

```json
{
  "scripts": {
    "preinstall": "echo 'going to install'"
  },
  "engines": {
    "node": "12.x",
    "yarn": "please-use-pnpm",
    "npm": "please-use-yarn",
    "pnpm": "please-use-yarn"
  },
  "engineStrict": true
}
```

About `engineStrict`, the fix is as easy as `echo 'engine-strict=true' > .npmrc`, but committing `.npmrc` to GitHub will cause GitGuardian errors.

About [preinstall](https://stackoverflow.com/questions/41076172/force-yarn-install-instead-of-npm-install-for-node-module), it is near perfect for first installs, but...

## [PNPM](https://pnpm.js.org/)

PNPM is another big topic. Many modules does not play well with `symlinks`, even with `echo 'shamefully-hoist=true' > .npmrc`.

Lately, I also have one annoying error with PNPM and `@vue/cli`.

```
 DONE  Compiled successfully in 24962ms                                                                                                1:43:39 AM

ERROR in /Users/patarapolw/projects/wk-extra-web/packages/web/src/app/index.ts(38,14):
38:14 Property '$store' does not exist on type 'App'.
    36 |         alert(e)
    37 |       } else {
  > 38 |         this.$store.commit('SET_API_KEY', this.loginKey)
       |              ^
    39 |       }
    40 |     }
    41 |   }
Version: typescript 3.9.7
Time: 3420ms

  App running at:
  - Local:   http://localhost:8080/ 
  - Network: http://192.168.1.3:8080/

  Note that the development build is not optimized.
  To create a production build, run pnpm run build.
```

And, creating local `*.d.ts` doesn't help (so, it is not about symlinks?); but changing to Yarn helps.

## Yarn

I also see that there is Yarn version 2, [which still should only be enabled on per project basis](https://yarnpkg.com/getting-started/install#per-project-install).

But I cannot use it with Vue CLI...

```
-------------------------------------------------------------------------------------------------------------------------------------------------
~/projects/wk-extra-web/packages/web(website*) » yarn set version berry                                 130 ↵ patarapolw@Pacharapols-MacBook-Air
Resolving berry to a url...
Downloading https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js...
Saving it into /Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs...
Updating /Users/patarapolw/projects/wk-extra-web/packages/web/.yarnrc.yml...
Done!
-------------------------------------------------------------------------------------------------------------------------------------------------
~/projects/wk-extra-web/packages/web(website*) » yarn                                                         patarapolw@Pacharapols-MacBook-Air
➤ YN0065: Yarn will periodically gather anonymous telemetry: https://yarnpkg.com/advanced/telemetry
➤ YN0065: Run yarn config set --home enableTelemetry 0 to disable

➤ YN0000: ┌ Resolution step
➤ YN0001: │ HTTPError: fork-ts-checker-webpack-plugin-v5@npm:5.1.0: Response code 404 (Not Found)
    at o.<anonymous> (/Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:23:12912)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
➤ YN0000: └ Completed in 9.36s
➤ YN0000: Failed with errors in 9.36s
-------------------------------------------------------------------------------------------------------------------------------------------------
~/projects/wk-extra-web/packages/web(website*) » yarn dev                                                 1 ↵ patarapolw@Pacharapols-MacBook-Air
Internal Error: @wk-extra/web@workspace:.: This package doesn't seem to be present in your lockfile; try to make an install to update your resolutions
    at H.getCandidates (/Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:2:298255)
    at i.getCandidates (/Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:2:287498)
    at /Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:2:308721
    at Array.map (<anonymous>)
    at ie.resolveEverything (/Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:2:308437)
    at async ie.applyLightResolution (/Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:2:330958)
    at async ie.restoreInstallState (/Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:2:330688)
    at async Re.execute (/Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:2:87214)
    at async Re.validateAndExecute (/Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:2:559450)
    at async j.run (/Users/patarapolw/projects/wk-extra-web/packages/web/.yarn/releases/yarn-berry.cjs:17:19046)
```

Still, I believe that Yarn is currently the best bet. Not only for features and speed, but also for official supports.