bitwarden / clients

Bitwarden client apps (web, browser extension, desktop, and cli).
https://bitwarden.com
Other
9.17k stars 1.24k forks source link

CLI dev env setup will fail without a webpack installed globally #3754

Closed konradbartecki closed 2 years ago

konradbartecki commented 2 years ago

Steps To Reproduce

On a new clean dev environment:

  1. clone the repo
  2. npm ci
  3. cd apps/cli
  4. npm run build:watch

Expected Result

CLI app builds

Actual Result

App will either silently fail build or complain about missing webpack.

npm run build:watch

> @bitwarden/cli@2022.9.0 build:watch /Users/konrad/Projects/bitwarden-clients/apps/cli
> webpack --watch

sh: webpack: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! @bitwarden/cli@2022.9.0 build:watch: `webpack --watch`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the @bitwarden/cli@2022.9.0 build:watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm run build:watch

> @bitwarden/cli@2022.9.0 build:watch /Users/konrad/Projects/bitwarden-clients/apps/cli
> webpack --watch

One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
 - webpack-cli (https://github.com/webpack/webpack-cli)
   The original webpack full-featured CLI.
We will use "npm" to install the CLI via "npm install -D".
Do you want to install 'webpack-cli' (yes/no): yes
Installing 'webpack-cli' (running 'npm install -D webpack-cli')...
npm WARN webpack-cli@4.10.0 requires a peer of webpack@4.x.x || 5.x.x but none is installed. You must install peer dependencies yourself.
npm WARN @webpack-cli/configtest@1.2.0 requires a peer of webpack@4.x.x || 5.x.x but none is installed. You must install peer dependencies yourself.

+ webpack-cli@4.10.0
updated 1 package and audited 245 packages in 4.801s

18 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Error: Cannot find module 'webpack-cli'
Require stack:
- /usr/local/lib/node_modules/webpack/bin/webpack.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at /usr/local/lib/node_modules/webpack/bin/webpack.js:143:5
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/local/lib/node_modules/webpack/bin/webpack.js' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @bitwarden/cli@2022.9.0 build:watch: `webpack --watch`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @bitwarden/cli@2022.9.0 build:watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Screenshots or Videos

No response

Additional Context

Installing multiple versions of following packages fixes the problem:

Operating System

macOS

Operating System Version

macOS 12.6

Shell

Bash

Build Version

6.14.12

Hinton commented 2 years ago

Webpack should already be installed in the root node_modules at the repository base. Is it possible you've run npm ci or npm i from the cli directory? Since that might cause similar issues to what you've experienced.

konradbartecki commented 2 years ago

I checked again:

npm run build:watch

> @bitwarden/cli@2022.9.0 build:watch /Users/konrad/Projects/bitwarden-clients/apps/cli
> webpack --watch

sh: webpack: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! @bitwarden/cli@2022.9.0 build:watch: `webpack --watch`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the @bitwarden/cli@2022.9.0 build:watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/konrad/.npm/_logs/2022-10-13T14_09_35_067Z-debug.log

Is this only my env issue or other people have the same issue? I managed to get this working when I had webpack installed globally. What does your npm list -g | grep webpack show?

djsmith85 commented 2 years ago

Not all of these are related to bitwarden projects:

>npm list -g
C:\Program Files\nodejs -> .\
├── @angular/cli@13.2.2
├── @compodoc/compodoc@1.1.18
├── corepack@0.10.0
└── npm@8.1.2

This must be an environment related issue. Any errors when running npm ci?

konradbartecki commented 2 years ago

Environment: commit 96aba0f994d640b94084d45a5f7cf38939bc28b8 npm version: 6.14.12 macOS 12.6 fish shell

at root directory npm ci

> nice-napi@1.0.2 install /Users/konrad/Projects/bitwarden-clients/node_modules/nice-napi
> node-gyp-build

> esbuild@0.14.49 postinstall /Users/konrad/Projects/bitwarden-clients/node_modules/esbuild
> node install.js

> utf-8-validate@5.0.9 install /Users/konrad/Projects/bitwarden-clients/node_modules/utf-8-validate
> node-gyp-build

> tldjs@2.3.1 postinstall /Users/konrad/Projects/bitwarden-clients/node_modules/tldjs
> node ./bin/postinstall.js

> core-js@2.6.12 postinstall /Users/konrad/Projects/bitwarden-clients/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

> core-js@3.24.0 postinstall /Users/konrad/Projects/bitwarden-clients/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

> bufferutil@4.0.6 install /Users/konrad/Projects/bitwarden-clients/node_modules/bufferutil
> node-gyp-build

> fsevents@1.2.13 install /Users/konrad/Projects/bitwarden-clients/node_modules/glob-watcher/node_modules/fsevents
> node install.js

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node

> es5-ext@0.10.61 postinstall /Users/konrad/Projects/bitwarden-clients/node_modules/es5-ext
>  node -e "try{require('./_postinstall')}catch(e){}" || exit 0

> lzma-native@8.0.6 install /Users/konrad/Projects/bitwarden-clients/node_modules/lzma-native
> node-gyp-build

> electron@19.0.8 postinstall /Users/konrad/Projects/bitwarden-clients/node_modules/electron
> node install.js

> fsevents@1.2.13 install /Users/konrad/Projects/bitwarden-clients/node_modules/watchpack-chokidar2/node_modules/fsevents
> node install.js

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node

> @compodoc/compodoc@1.1.19 postinstall /Users/konrad/Projects/bitwarden-clients/node_modules/@compodoc/compodoc
> opencollective-postinstall || exit 0

Thank you for using @compodoc/compodoc!
If you rely on this package, please consider supporting our open collective:
> https://opencollective.com/compodoc/donate

> @bitwarden/clients@0.0.0 prepare /Users/konrad/Projects/bitwarden-clients
> husky install

husky - Git hooks installed
added 3236 packages in 53.452s

then

cd apps/cli npm run build:watch

sh: webpack: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! @bitwarden/cli@2022.9.0 build:watch: `webpack --watch`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the @bitwarden/cli@2022.9.0 build:watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/konrad/.npm/_logs/2022-10-14T15_07_49_311Z-debug.log

contents of debug log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build:watch' ]
2 info using npm@6.14.12
3 info using node@v14.16.1
4 verbose run-script [ 'prebuild:watch', 'build:watch', 'postbuild:watch' ]
5 info lifecycle @bitwarden/cli@2022.9.0~prebuild:watch: @bitwarden/cli@2022.9.0
6 info lifecycle @bitwarden/cli@2022.9.0~build:watch: @bitwarden/cli@2022.9.0
7 verbose lifecycle @bitwarden/cli@2022.9.0~build:watch: unsafe-perm in lifecycle true
8 verbose lifecycle @bitwarden/cli@2022.9.0~build:watch: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/konrad/Projects/bitwarden-clients/apps/cli/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands
9 verbose lifecycle @bitwarden/cli@2022.9.0~build:watch: CWD: /Users/konrad/Projects/bitwarden-clients/apps/cli
10 silly lifecycle @bitwarden/cli@2022.9.0~build:watch: Args: [ '-c', 'webpack --watch' ]
11 info lifecycle @bitwarden/cli@2022.9.0~build:watch: Failed to exec build:watch script
12 verbose stack Error: @bitwarden/cli@2022.9.0 build:watch: `webpack --watch`
12 verbose stack spawn ENOENT
12 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack     at ChildProcess.emit (events.js:315:20)
12 verbose stack     at maybeClose (internal/child_process.js:1048:16)
12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
13 verbose pkgid @bitwarden/cli@2022.9.0
14 verbose cwd /Users/konrad/Projects/bitwarden-clients/apps/cli
15 verbose Darwin 21.6.0
16 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build:watch"
17 verbose node v14.16.1
18 verbose npm  v6.14.12
19 error code ELIFECYCLE
20 error syscall spawn
21 error file sh
22 error errno ENOENT
23 error @bitwarden/cli@2022.9.0 build:watch: `webpack --watch`
23 error spawn ENOENT
24 error Failed at the @bitwarden/cli@2022.9.0 build:watch script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]
djsmith85 commented 2 years ago

Not sure if this is the root cause, but I noticed you are using an older version of npm.

Please update it to at least v8 and also check if there are any other tools needed/or need updating based on our setup instructions in our Contribution Guidelines

konradbartecki commented 2 years ago

Tested with a recent Ubuntu VM and there it works out of the box. Turns out Volta made my shell point to an older npm. When I made my shell to point to an npm v8 then everything works.

Side note, when I use an older npm version I do not get this message:

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@bitwarden/clients@0.0.0',
npm WARN EBADENGINE   required: { node: '~16', npm: '~8' },
npm WARN EBADENGINE   current: { node: 'v18.11.0', npm: '8.19.2' }
npm WARN EBADENGINE }

It is shown only when node version differs.

Issue can be closed, thanks a lot!