DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

Would you use NPM (not Yarn or PNPM) in Sep 2020?

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

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

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

About preinstall, it is near perfect for first installs, but...

PNPM

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.
Enter fullscreen mode Exit fullscreen mode

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.

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)
Enter fullscreen mode Exit fullscreen mode

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

Top comments (2)

 
maxdevjs profile image
maxdevjs

never did. But now I am curious...

Collapse
 
maxdevjs profile image
maxdevjs

Wait... to install node modules with sudo...?