moment: './locale' path not found in moment/src/lib/locale/locales.js
WARNING in ./node_modules/moment/src/lib/locale/locales.js
Module not found: Error: Can't resolve './locale' in 'D:\project-fed\ecloud\client-web\node_modules\moment\src\lib\locale'
I found that there is something wrong with the function below
function loadLocale(name) {
var oldLocale = null;
// TODO: Find a better way to register and load all the locales in Node
if (!locales[name] && (typeof module !== 'undefined') &&
module && module.exports) {
try {
oldLocale = globalLocale._abbr;
var aliasedRequire = require;
aliasedRequire('./locale/' + name);
getSetGlobalLocale(oldLocale);
} catch (e) {}
}
return locales[name];
}
aliasedRequire('./locale/' + name);
, should it be ../locale/
?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 22
- Comments: 54 (1 by maintainers)
Commits related to this issue
- Compatibility fix for `moment` update Running `ng build` after updating all the packages revealed a problem with just one: moment going from 2.24.0 => 2.25.1 ``` WARNING in ./node_modules/moment/src/... — committed to chef/automate by msorens 4 years ago
- Build 2.25.1 — committed to moment/moment by ichernev 4 years ago
- Compatibility fix for `moment` update Running `ng build` after updating all the packages revealed a problem with just one: moment going from 2.24.0 => 2.25.1 ``` WARNING in ./node_modules/moment/src/... — committed to chef/automate by msorens 4 years ago
- fix: fix moment locale resolve issue https://github.com/moment/moment/issues/4505 — committed to ilovefibos/fibostoolkit by Zkffkah 4 years ago
- Fix moment issue https://github.com/moment/moment/issues/4505 — committed to forember/theia-electron by bencehornak 4 years ago
Just import like below and it’s work :
import moment from ‘moment/moment’;
Hello Guys! I faced the same issue from last few hours and finally I have resolved it through changing moment version.
In the above comments i saw the final solution.
Reason: moment release the new version 17 hours ago from 2.24.0 to 2.25.0
Solution: Step 1: change the versions
Step 2: If you are using yarn please add resolutions in your package.json file like this “dependencies” { “moment”: “2.24.0”, “moment-timezone”: “^0.5.28” }, “resolutions”: { “moment”: “2.24.0” },
Thank You.
I do
and that works.
https://github.com/moment/moment/issues/2979
Looks like it’s been the case for years, why they won’t fix it I have no idea. I just ran into this as well when trying to use jsnext:main in webpack instead of main.
My work-around to keep using jsnext:main in webpack for the other packages that have properly transpiled es6 code: use an alias to force webpack to use moment.js directly as it is specified in pkg.main
... resolve: { alias: { moment$: path.resolve(root_dir, "node_modules/moment/moment.js") } }
my workaround is to get back to 2.24.0
for anyone else experiencing this issue, i had to also force the versions of moments that other packages in my
node_modules/
folder pulled in as dependencies to v2.24.0 as wellusing yarn, adding this line to package.json sorted things for me
Rolling back to v.2.24.0 worked for me as well.
You can run this commands for now.
npm install moment@2.24.0 --save
I had the same case and when I search somehow antd was using moment as a dependency and i hope the moment issue will be closed in next release while i saw they released a new version so please first try the latest version which is 2.25.1 then try to add moment as a dependency.
Thank You!
Even if you have, following block. The package-lock.json will create a new version i.e. 2.5.1. So change it to “moment”: “2.24.0” till the issue is addressed. “dependencies” { “moment”: “^2.24.0”, ----------------> “moment”: “2.24.0” },
I am facing the same issue after updating
Where should this line be put?
This alias with the WebPack config fixes an issue for me:
Thanks . Its work fine. just import the line bellow: import * as moment from ‘moment/moment’;
I have fix this error, at least for me.
I went to node_modules/moment/src/lib/locale/ Modified the locales.js file, ctrl+f and search
'./locale'+name
line. Change it to'./'+name
. I don’t know why is pointing to same folder and ‘/.locale’ + name, this is why the error says can’t resolve ./localeTo be honest, I copied the original line and commented just above, if in the future an error shows up.
If it helps, thumbs up. This kind of errors are the worse…
i rolled back to 2.24.0 but still having same warning while using node
Yup, removing
"module": "./src/moment.js",
frompackage.json
made the warning go away for me. BTW, mine is aReact
app –create-react-app
and I’m using"moment": "^2.25.1"
. Even though I was using the latest version, I was still getting this error but updating thepackage.json
seems to fix the issue. Thanks @ApacheExloooks like root of issue was caused by
"module"
field inpackage.json
(https://github.com/moment/moment/commit/9ce89e7fea881b39be23b8c0646f7ef7817985d9)here is PR to fix it https://github.com/moment/moment/pull/5503
For those using the command “yarn create react-app <app name>”, the fix is to edit node_modules/react-scripts/config/webpack.config.js to add the alias like below.
Insert the above line into the alias block at line number 311.
Another way to solve this is to replace moment.js with Day.js. Follow the instructions in this url to use react-app-rewired >> https://ant.design/docs/react/use-with-create-react-app. Modify package.json according to the instruction. Then create a config-overrides.js in the root folder like below. This has the benefit of shrinking the js from 231.11kb to 11.11kb according to this https://github.com/ant-design/antd-dayjs-webpack-plugin.
I just rolled back to “^2.18.1” and everything seems working fine
@marcelogarbin oh sorry I haven’t messed with Laravel since version 4. I apologize but .I don’t know how to make it work with laravel mix.
inside the webpack? I am thinking about how to do this with Laravel Mix…