0

I am using Vite+React. I am getting error while running npm run dev.

"[ERROR] Could not resolve require("./locale/**/*") node_modules/moment-with-locales-es6/node_modules/moment/min/moment-with-locales.min.js:1:16645: 1 │ ...e&&module&&module.exports)try{b=Bf._abbr,require("./locale/"+a),$a(b)}catch(a){}return Ff[a]}function $a(a,b){v..."

I am using below versions of the packages.

  • React: 18.3.1
  • Vite: 5.4.1
  • moment: 2.30.1
  • moment-with-locales-es6: 2.18.1

I also added below code in vite.config.js file.

 resolve: {
    alias: {`your text`
        'moment$': 'moment/min/moment.with-locales.js',
    },
},

How to solve this problem?

I tried with multiple versions of Moment.js like 2.18.1, 2.25.2 etc.

1 Answer 1

1

I was able to solve this error after changing import syntax from

import moment from "moment"

to

import * as moment from "moment/moment"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.