eduolalo / moment-business-days

This is a momentJS plugin that allows you to use only business days (Monday to Friday)
MIT License
240 stars 67 forks source link

Cannot import moment-business-days #111

Open IAPBenediktZwoelfer opened 9 months ago

IAPBenediktZwoelfer commented 9 months ago

app.js:56 TypeError: Cannot set properties of undefined (setting 'isHoliday') at node_modules/moment-business-days/index.js (index.js:7:11) at __require2 (chunk-DA74IYYC.js?v=31bda342:17:50) at index.js:248:1

simplecommerce commented 7 months ago

app.js:56 TypeError: Cannot set properties of undefined (setting 'isHoliday') at node_modules/moment-business-days/index.js (index.js:7:11) at __require2 (chunk-DA74IYYC.js?v=31bda342:17:50) at index.js:248:1

Did you ever figure out how to fix it?

wahibimoh commented 5 months ago

I fixed it by adding the following line to vite.config.js: resolve: {mainFields: []},

like this: (you can ignore the rest)

import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'

export default defineConfig({
  build: {
    //minify: false,
  },
  esbuild: { legalComments: 'none' },
  resolve: {mainFields: []}, //<------ this fixed it!
  plugins: [svelte()],
})
alexeyvokin commented 4 months ago

This solution didn't work for me:

resolve: {mainFields: []},

Does anyone have any idea how this can be fixed in a better way?

Environment: 1) vite 5.2.9 2) @originjs/vite-plugin-commonjs 1.0.3 3) @vitejs/plugin-vue 5.0.4

simplecommerce commented 4 months ago

This solution didn't work for me:

resolve: {mainFields: []},

Does anyone have any idea how this can be fixed in a better way?

Environment:

  1. vite 5.2.9
  2. @originjs/vite-plugin-commonjs 1.0.3
  3. @vitejs/plugin-vue 5.0.4

I haven't tried the suggested fix, I decided to migrate to Luxon instead.

wahibimoh commented 4 months ago

Yep, that is what I did as well

On Mon, Apr 22, 2024, 1:10 PM Kheang Hok Chin @.***> wrote:

This solution didn't work for me:

resolve: {mainFields: []},

Does anyone have any idea how this can be fixed in a better way?

Environment:

  1. vite 5.2.9
  2. @originjs/vite-plugin-commonjs 1.0.3
  3. @vitejs/plugin-vue 5.0.4

I haven't tried the suggested fix, I decided to migrate to Luxon instead.

— Reply to this email directly, view it on GitHub https://github.com/eduolalo/moment-business-days/issues/111#issuecomment-2069005730, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPUZ7OTGWLBDLNKQGZ5PTTY6TO3BAVCNFSM6AAAAABABEXIW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRZGAYDKNZTGA . You are receiving this because you commented.Message ID: @.***>

yodeyer commented 3 months ago

I think the issue is that the latest published version still uses require : https://github.com/eduolalo/moment-business-days/blob/v1.2.0/index.js, which is not defined in vite. The master branch supports ESM imports, but is not published on NPM