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

Add dayjs-nuxt to nuxt.config.ts modules, then typescript not working #48

Open
boss006133 opened this issue Aug 22, 2024 · 1 comment
Open

Comments

@boss006133
Copy link

reproduction zip:
test-typescript.zip

I just create a new nuxt3 app, and add only one module(dayjs-nuxt), then I auto import a const from nuxt.config.ts like the code below

nuxt.config.ts

export default defineNuxtConfig({
  compatibilityDate: "2024-04-03",
  devtools: { enabled: true },
  modules: ["dayjs-nuxt"],
  imports: {
    dirs: ["constants/others"],
  },
  typescript: {
    typeCheck: true,
  },
})

image

and make the typescript not working

image

package.json

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "@nuxt/devtools": "latest",
    "dayjs-nuxt": "^2.1.9",
    "sass": "1.77.6",
    "sass-loader": "^13.3.2",
    "typescript": "^5.5.4",
    "vue-tsc": "^2.0.29"
  },
  "dependencies": {
    "nuxt": "^3.12.4",
    "nuxt-viewport": "^2.1.5",
    "vue": "latest"
  }
}

If I remove "dayjs-nuxt" from nuxt.config.ts modules, then typescript intellisense works fine

@Riadz
Copy link

Riadz commented Sep 7, 2024

@boss006133 same issue for me, i just reverted to using dayjs package directly,
i created project/utils/dayjs.ts:

import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime.js'
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'
import isBetween from 'dayjs/plugin/isBetween'
import duration from 'dayjs/plugin/duration'
import 'dayjs/locale/ar'

dayjs.extend(relativeTime)
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(isBetween)
dayjs.extend(duration)

export const $dayjs = dayjs

this will make $dayjs(...) available in both template and script to use,
am sure this is not the best way to do it, but until this package is fixed this should do.

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

2 participants