Webpack-cli: importLocal check may invoke wrong version of WDS in a Yarn workspace

Created on 14 May 2020  路  5Comments  路  Source: webpack/webpack-cli

  • Operating System: Ubuntu 16
  • Node Version: 12.16.1
  • NPM Version: 6.13.4
  • webpack Version: 4.43.0
  • webpack-dev-server Version: 3.11.0
  • Browser: N/A
  • [x] This is a bug
  • [x] This is a modification request

Code

Folder structure (including installed packages):

- yarn.lock
- node_modules // workspace root
  - import-local
  - [email protected]
- my-project
  - webpack.config.js
  - package.json // includes an npm script to invoke WDS
  - node_modules
    - [email protected]

Expected Behavior

When I invoke WDS from the nested my-project directory it should use v3.11.0

Actual Behavior

v3.11.0 is invoked correctly at first, but the importLocal check in the /bin/webpack-dev-server.js script causes v3.7.2 to be used. This is because of a bug in the import-local package (which I have reported here) where it doesn't take into account that there might be multiple node_modules folders, like in a Yarn workspace.

The bug is intermittent because it depends on Yarn's hoisting behaviour; if import-local had been placed in the nested node_modules directory then v3.11.0 would be used as intended.

The bug can occur for any versions of WDS; 3.11.0 and 3.7.2 are just the versions in my project.

For Bugs; How can we reproduce the behavior?

It's tricky to reproduce this reliably as it depends on Yarn's hoisting behaviour, but it should be possible to manually recreate a folder structure like the above and observe the behaviour.

For Features; What is the motivation and/or use-case for the feature?

I would like to propose a flag to skip the importLocal check. In my scenario I can be sure there won't be a global installation of WDS, so there's no need to run the check at all, which would avoid any issues like this.

enhancement

All 5 comments

@elliotdavies let's wait answer from @sindresorhus

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@webpack/cli-team here simple fix, we need add WEBPACK_CLI_SKIP_IMPORT_LOCAL here https://github.com/webpack/webpack-cli/blob/master/packages/webpack-cli/bin/cli.js#L16 (if defined we don't use import-local package)

wip

Thanks @anshumanv!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aleksandrlat picture aleksandrlat  路  3Comments

jbottigliero picture jbottigliero  路  5Comments

anyulled picture anyulled  路  4Comments

billyjanitsch picture billyjanitsch  路  3Comments

luillyfe picture luillyfe  路  4Comments