Moment: Webpack - Critical dependency: the request of a dependency is an expression with 2.25.0

Created on 1 May 2020  ·  35Comments  ·  Source: moment/moment

This morning I upgraded moment from 2.24.0 to 2.25.0 and started getting this warning from my Webpack build :
Critical dependency: the request of a dependency is an expression

Versions I'm using :
gulp - 4.0.2
webpack - 4.43.0
babel - 7.9.6

No other updates occurred in between. Only moment.js got updated and the warning appeared.

Most helpful comment

Same here, locking the package version to 2.24.0 helps for now...

All 35 comments

same issue

same issue
after installing moment in laravel vue app.
WARNING in ./node_modules/moment/src/lib/locale/locales.js 78:12-82:13 Critical dependency: the request of a dependency is an expression @ ./node_modules/moment/src/lib/locale/locale.js @ ./node_modules/moment/src/moment.js @ ./resources/js/app.js @ multi ./resources/js/app.js ./resources/sass/app.scss

Same here, locking the package version to 2.24.0 helps for now...

Same problem over here! Critical!

I have had the same issue! Locked mine to 2.24.0 and fixed my build

Seconded

Same here. 2.25.0 gives this issue but not 2.24.0. Changes at 2092:16-2096:17 in moment.js is the root.

Same issue, but strangely only when running as dev (this is a nuxt project) The issues seems to be in src/lib/locale/locales.js line 78 - 82,

Changing:
```javascript
aliasedRequire(
(typeof __dirname !== undefined ? __dirname : '.') +
'/locale/' +
name
);
to: javascript
aliasedRequire('../locale/' + name);
````
Fixes the issue for me

I get it both on dev and prod builds with my setup.

Same here, locking the package version to 2.24.0 helps for now...

Yeah, that's the obvious workaround, but not really a solution :-).

I am also getting the same warning and getting following console errors, in a web browser for angular application while calling moment.format().

ERROR TypeError: __WEBPACK_IMPORTED_MODULE_2_moment__ is not a function
(main.bundle.js:11539)
Show 102 more frames

same here

Confirmed as well

Wait a second -- this is warning, not an error. Does it still produce a bundle?

With moment 2.25.0:

% ./node_modules/.bin/webpack
Hash: 42b60d02778538c038dc
Version: webpack 4.43.0
Time: 497ms
Built at: 05/01/2020 4:56:43 PM
    Asset      Size  Chunks             Chunk Names
bundle.js  72.2 KiB       0  [emitted]  main
Entrypoint main = bundle.js
[13] ./node_modules/moment/src/lib/units/month.js + 1 modules 9.92 KiB {0} [built]
     |    2 modules
[26] ./node_modules/moment/src/lib/create/valid.js + 1 modules 1.88 KiB {0} [built]
     |    2 modules
[36] ./node_modules/moment/src/lib/create/from-anything.js + 8 modules 25.1 KiB {0} [built]
     |    9 modules
[46] (webpack)/buildin/harmony-module.js 573 bytes {0} [built]
[47] ./node_modules/moment/src/lib/locale sync 160 bytes {0} [optional] [built]
[48] ./src/index.js + 54 modules 84.6 KiB {0} [built]
     | ./src/index.js 62 bytes [built]
     |     + 54 hidden modules
    + 43 hidden modules

WARNING in ./node_modules/moment/src/lib/locale/locales.js 78:12-82:13
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/moment/src/lib/locale/locale.js
 @ ./node_modules/moment/src/moment.js
 @ ./src/index.js

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

And it works.

With [email protected]:

% ./node_modules/.bin/webpack
Hash: c16dbd62d51ed42203b2
Version: webpack 4.43.0
Time: 559ms
Built at: 05/01/2020 4:58:27 PM
    Asset     Size  Chunks                    Chunk Names
bundle.js  263 KiB       0  [emitted]  [big]  main
Entrypoint main [big] = bundle.js
[128] ./src/index.js 62 bytes {0} [built]
[129] (webpack)/buildin/module.js 497 bytes {0} [built]
[130] ./node_modules/moment/locale sync ^\.\/.*$ 3 KiB {0} [optional] [built]
    + 128 hidden modules

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets: 
  bundle.js (263 KiB)

WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
  main (263 KiB)
      bundle.js


WARNING in webpack performance recommendations: 
You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
For more info visit https://webpack.js.org/guides/code-splitting/

And it still works.

Wait a second -- this is warning, not an error. Does it still produce a bundle?

Yes, it does. Still - annoying, wrong and makes the build output full of crappy traces.

I'm also seeing this, but only in production builds via our CI.

@jontybrook I was seeing the same behavior but after nuking node_modules folder, I was able to reproduce this locally.

The code with __dirname which was fixing an issue for react-native had to be reverted so that you (webpack users) can look at a better console output.

Fixed in 2.25.1

This has nothing to do with better console output...but rather less than ideally tested code breaking builds for MANY MANY people!

Glad to hear its been fixed and published minutes ago though - spent the last many hours digging into on our end trying to find the cause

This has nothing to do with better console output...but rather less than ideally tested code breaking builds for MANY MANY people!

Exactly ! Warning today is a potential error tomorrow.

It was much worse than a warning...if you by chance were running moment-timezone which dynamically pulls in latest version of moment, this caused a full breaking of code!

Wait a second -- this is warning, not an error. Does it still produce a bundle?

If only producing a bundle was the only desired result...

The code with __dirname which was fixing an issue for react-native had to be reverted so that you (webpack users) can look at a better console output.

Fixed in 2.25.1

Why the sarcasm ?! Clean output is important. In my setup I’ve put stats and metrics which are important for me and flooding it with unnecessary stuff makes it tiresome to read and slows my work at the very least. Then it comes the fact that a warning is always something that should not be ignored in the long term. Last, but actually first - it turns out to be really breaking for some setups as @agrohs reported. So ... sarcasm is not well placed here I beleive. Thanks for fixing it, though.

Glad to see this fixed. Will continue with 2.24.0 till a later version or may keep it... took way too long to figure out why our web app was broken this morning after a deploy.

"You" webpack users... aka a large portion of web app developers. We don't currently have any extra data coming from our webpack process, so I don't want to look at better console output, I just want it to work.

The code with __dirname which was fixing an issue for react-native had to be reverted so that you (webpack users) can look at a better console output.

Fixed in 2.25.1

Sarcasm aside, v2.25.1 doesn't actually fix anything (the Module not found warning is still there). I typically refrain from being critical of open source contributors who are volunteering their time, but please don't have an attitude towards users who are simply reporting issues. And yes, warnings are there for a reason. Ignoring them obscures all sorts of other info and usually leads to something broken down the road.

This issue should not be closed...it is a breaking change for moment-timezone users who are using webpack, not just an issue of showing a warning (and affecting an enormously large number of people)

same problem
not fix 2.25.0
not fix 2.25.1
not fix 2.25.2

I want you to revert to the original version.

Operation check environment
https://github.com/standard-software/partsjs/tree/v5.0.0
package.json

Guy this is not fixed! Can we not close defects until they are resolved especially when they break existing builds such as Webpack?! @ichernev please re-open this as it's not resolved! This is going to break many people who rely on MomentJS and use it with vanilla Webpack.

Hi, BUMP!, this is breaking my build also, not fixed!.

I just update moment with npm i moment and it solved it

Was this page helpful?
0 / 5 - 0 ratings