Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import moment-business-days #111

Open
IAPBenediktZwoelfer opened this issue Nov 30, 2023 · 7 comments
Open

Cannot import moment-business-days #111

IAPBenediktZwoelfer opened this issue Nov 30, 2023 · 7 comments

Comments

@IAPBenediktZwoelfer
Copy link

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
Copy link

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
Copy link

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
Copy link

alexeyvokin commented Apr 22, 2024

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
Copy link

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
Copy link

wahibimoh commented Apr 22, 2024 via email

@yodeyer
Copy link

yodeyer commented May 27, 2024

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

@samausir
Copy link

Importing from the master branch directly did work as suggested above.
"moment-business-days": "https://github.com/eduolalo/moment-business-days#master",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants