I'm using "moment": "^2.29.1", "moment-range": "^4.0.2",
to get the range between two dates.
Vite with Vue3 and typescript.
Locally, eveything works fine. But when deploying to Netlify I get the following error:
Cannot add property range, object is not extensible at Object.o [as extendMoment]
Importing moment:
import * as moment from "moment";
import { extendMoment } from "moment-range";
const Moment = extendMoment(moment);
Here is what let me make moment-range work in both watch and build versions of vite app:
import moment from 'moment'
import * as MomentRange from 'moment-range'
const momentJs = MomentRange.extendMoment(moment)
Also had to add following to vite.config.js:
export default defineConfig({
...
resolve: {
alias: [
{
find: 'moment-range',
replacement: path.resolve("./node_modules/moment-range/dist/moment-range"),
},
...
],
},
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.