vuetify-module icon indicating copy to clipboard operation
vuetify-module copied to clipboard

Cannot find module 'vuetify/lib/util/colors' in nuxt.config.js

Open jscottsf opened this issue 5 years ago • 27 comments

Module version 1.0.2

Describe the bug Production app throws Cannot find module 'vuetify/lib/util/colors' in nuxt.config.js.

To Reproduce Specify the following in next.config.js for custom colors:

import colors from 'vuetify/es5/util/colors'

  vuetify: {
    customVariables: ['~/assets/variables.scss'],
    theme: {
      dark: true,
      themes: {
        dark: {
          primary: colors.blue.darken2,
          accent: colors.grey.darken3,
          secondary: colors.amber.darken3,
          info: colors.teal.lighten1,
          warning: colors.amber.base,
          error: colors.deepOrange.accent4,
          success: colors.green.accent3
        }
      }
    }
  },

Works in dev since the dev dependencies are available. If you build for production in a Docker container, throws the error Cannot find module 'vuetify/lib/util/colors' since dev dependencies are not loaded when NODE_ENV is production.

jscottsf avatar Aug 06 '19 06:08 jscottsf

Hi @jscottsf ,

~~I think that in your case it's totally fine having the module in dependencies, as you indeed need your production Docker container to install the dependency to build your application.~~

~~You can still let the module as a devModule around your configuration, so that the module is not registered when using nuxt start :).~~

EDIT : Check my last comment

Also, please update to the last version of the module (1.2.0) 😉

kevinmarrec avatar Aug 06 '19 08:08 kevinmarrec

@jscottsf See this new option (if you upgrade the module to 1.2.0) : https://github.com/nuxt-community/vuetify-module#optionspath

Defining options like this will make the Vuetify colors will be bundled by Webpack at build step, it should fix your issue.

Ultimate solution would be moving @nuxtjs/vuetify to dependencies.

kevinmarrec avatar Aug 06 '19 08:08 kevinmarrec

Thank you for the fast reply.

Yes, for the short term I moved @nuxtjs/vuetify to dependencies.

I will definitely update and check out optionsPath.

Thx! 👍

jscottsf avatar Aug 06 '19 15:08 jscottsf

I feel like this should be more prominent in the README. when using the Nuxt project generator, it automatically installs this module as a dev-dependency and places all the vuetify config in nuxt.config.js.

So any user who does not dig in to the issues section will be blind to the issue until they try to do a production deployment.

morficus avatar Aug 23 '19 15:08 morficus

@morficus You're right but it's more likely create-nuxt-app that needs to be updated, could you please an issue there ? Thanks.

kevinmarrec avatar Aug 23 '19 16:08 kevinmarrec

@kevinmarrec fair point. I noticed create-nuxt-app is also still using v1.0.0 of this module. So they certainly do need to update.

morficus avatar Aug 23 '19 16:08 morficus

@morficus Well AFAIK, ^1.0.0 in package.json should install 1.x.x so it should install last version for fresh projects if i'm right.

kevinmarrec avatar Aug 23 '19 16:08 kevinmarrec

@jscottsf hey brother, did you find solution for that missing package ? i am facing the same problem in nuxt/vuetify.

N1t35h avatar Sep 10 '19 05:09 N1t35h

Still not fixed by default. I got mine working using the above solutions:

  1. Update @nuxtjs/vuetify to the lastest version
  2. In your package.json: move @nuxtjs/vuetify from devDependencies to dependencies

MarkSonn avatar Dec 22 '19 12:12 MarkSonn

@MarkSonn

Still not fixed by default. I got mine working using the above solutions:

  1. Update @nuxtjs/vuetify to the lastest version
  2. In your package.json: move @nuxtjs/vuetify from devDependencies to dependencies

Thnks! Your answers helped me 👍

agustiinlombardo avatar Jan 17 '20 03:01 agustiinlombardo

Using optionsPath is the way to go to not have Vuetify needed in dependencies. If you keep Vuetify imports in nuxt.config.js it's obvious you need Vuetify at runtime (so in dependencies)

kevinmarrec avatar Jan 17 '20 07:01 kevinmarrec

Can someone please reopen this issue. It is not fixed by default. I think making a new issue is counter-intuitive.

@manniL you seem quite active on here. Are you able to help please?

MarkSonn avatar Jul 01 '20 13:07 MarkSonn

Reopened

TheAlexLichter avatar Jul 03 '20 11:07 TheAlexLichter

I'm having a same problem too hoping they have a fix for here. Mine was NuxtJS + Vuetify tryiing to deploy to Firebase Hosting

https://prnt.sc/tzgyq2

jomellelastrilla avatar Aug 14 '20 10:08 jomellelastrilla

I'm having a same problem too hoping they have a fix for here. Mine was NuxtJS + Vuetify tryiing to deploy to Firebase Hosting

https://prnt.sc/tzgyq2

You need replace the "export default { ... }" to "module.exports = { ... }"

agustiinlombardo avatar Sep 03 '20 03:09 agustiinlombardo

This is the alternate solution that doesn't need @nuxtjs/vuetify to be moved from devDependencies to dependencies (currently working with Vercel).

  1. Create a vuetify.options.js in the root dir of the project and copy the vuetify settings from nuxt.config.js as follows
/*
vuetify.config.js
*/

import colors from 'vuetify/es5/util/colors'

export default {
  customVariables: ['~/assets/variables.scss'],
  optionsPath: './vuetify.options.js',
  theme: {
    dark: true,
    themes: {
      dark: {
        primary: colors.blue.darken2,
        accent: colors.grey.darken3,
        secondary: colors.amber.darken3,
        info: colors.teal.lighten1,
        warning: colors.amber.base,
        error: colors.deepOrange.accent4,
        success: colors.green.accent3
      }
    }
  }
}
  1. Replace the vuetify entry in nuxt.config.js with the following
...
vuetify: {
  optionsPath: './vuetify.options.js'
},
...

cdleon avatar Oct 03 '20 05:10 cdleon

The simple solution to fix the problem without moving this dependency to dev. It perfectly works on javascript and typescript.

  1. Example vuetify.options.ts
import colors from 'vuetify/src/util/colors'
import ru from 'vuetify/src/locale/ru'

export default {
  lang: {
    locales: { ru },
    current: 'ru',
  },
  theme: {
    dark: true,
    themes: {
      dark: {
        primary: colors.blue.darken2,
        accent: colors.grey.darken3,
        secondary: colors.amber.darken3,
        info: colors.teal.lighten1,
        warning: colors.amber.base,
        error: colors.deepOrange.accent4,
        success: colors.green.accent3,
      },
    },
  },
}
  1. Add vuetify dependency to transpile array in nuxt.config.js. It should look like this:
{
  vuetify: {
    customVariables: ['~/assets/variables.scss'],
    optionsPath: '~/vuetify.options.ts',
  },
  // Build Configuration (https://go.nuxtjs.dev/config-build)
  build: {
    transpile: [/vuetify/],
  },
}

P.S. You can try to check it via a docker multi-staging build.

FROM node:latest as builder
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn
COPY . ./
RUN yarn build

FROM node:alpine
WORKDIR /app
COPY package.json yarn.lock ./
ENV NODE_ENV=production
RUN yarn
COPY nuxt.config.js ./
COPY --from=builder /app/.nuxt ./.nuxt/
COPY --from=builder /app/static ./static/
EXPOSE 3000
ENV NUXT_HOST=0.0.0.0
ENTRYPOINT [ "yarn", "run" ]
CMD [ "start" ]

CrazyUmka avatar Nov 09 '20 15:11 CrazyUmka

I can develop the environment by converting docker base image node:14.15.3-alpine3.10 into node:14.15.3-buster.

pomcho555 avatar Jan 01 '21 07:01 pomcho555

@jscottsf See this new option (if you upgrade the module to 1.2.0) : https://github.com/nuxt-community/vuetify-module#optionspath

Defining options like this will make the Vuetify colors will be bundled by Webpack at build step, it should fix your issue.

Ultimate solution would be moving @nuxtjs/vuetify to dependencies.

Moving all @nuxtjs dependencies from devDependencies to dependencies helped. I don't understand why they were in dev in the first place.

StanleyMasinde avatar Feb 21 '21 18:02 StanleyMasinde

Still not fixed. Just created a fresh Nuxt project w/ Vuetify and it's busted when you deploy to production. 🤔

But many thanks to @MarkSonn for the easy & quick fix!

ffxsam avatar Mar 17 '21 01:03 ffxsam

Hi I am having same issue when I try to deploy site on netlify but its working fine on my local machine. Here is my package.json

{ "name": "dashboard-nuxt-app", "version": "1.0.0", "private": true, "scripts": { "dev": "nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate" }, "dependencies": { "@nuxtjs/axios": "^5.13.1", "@nuxtjs/vuetify": "^1.11.3", "chart.js": "^2.9.4", "core-js": "^3.9.1", "js-cookie": "^2.2.1", "nuxt": "^2.15.3", "sweetalert2": "^10.16.4", "vee-validate": "^3.4.5", "vue-chartjs": "^3.5.1", "vuex-map-fields": "^1.4.1", "vuex-persistedstate": "^4.0.0-beta.3" }, "devDependencies": { "eslint-config-prettier": "^8.1.0", "eslint-plugin-prettier": "^3.3.1", "prettier": "^2.2.1", "sass": "^1.32.8", "sass-loader": "^10.1.1" } }

chiragparekh avatar Apr 27 '21 09:04 chiragparekh

hello guys, I tried moving the @nuxtjs/vuetify module to the dependency from devDependency, it works quite well on netlify but on digital ocean provisioned server I have it gives me an error still stating cannot find module 'vuetify/es5/util/colors'. any help pls

narthkings avatar May 03 '21 06:05 narthkings

This is the alternate solution that doesn't need @nuxtjs/vuetify to be moved from devDependencies to dependencies (currently working with Vercel).

  1. Create a vuetify.options.js in the root dir of the project and copy the vuetify settings from nuxt.config.js as follows
/*
vuetify.config.js
*/

import colors from 'vuetify/es5/util/colors'

export default {
  customVariables: ['~/assets/variables.scss'],
  optionsPath: './vuetify.options.js',
  theme: {
    dark: true,
    themes: {
      dark: {
        primary: colors.blue.darken2,
        accent: colors.grey.darken3,
        secondary: colors.amber.darken3,
        info: colors.teal.lighten1,
        warning: colors.amber.base,
        error: colors.deepOrange.accent4,
        success: colors.green.accent3
      }
    }
  }
}
  1. Replace the vuetify entry in nuxt.config.js with the following
...
vuetify: {
  optionsPath: './vuetify.options.js'
},
...

It worked for me. I think this is the best solution. Thanks a lot! 👏🏼

Nechitadi avatar Nov 02 '21 16:11 Nechitadi

It sill an issue for me, I try to move from devDependencies to dependencies, try to use ~/ instead of ./, try to use last version of @nuxtjs/vuetify, try to use options directly in buildModules ['@nuxtjs/vuetify', {optionsPath: './vuetify.options.js'}. Nothing works :(

Reeska avatar Apr 04 '22 15:04 Reeska

I'm not sure if it is a good practice but setting NPM_CONFIG_PRODUCTION=false before install solved the issue for me. This tell npm to install also devDependencies.

btw I'm using an old version of nuxt, maybe is not needed anymore:

"dependencies": {
        "@nuxtjs/auth": "^4.9.1",
        "@nuxtjs/axios": "^5.3.6",
        "chart.js": "^2.9.4",
        "nuxt": "^2.0.0",
        "vue-chartjs": "^3.5.1"
    },
    "devDependencies": {
        "@nuxtjs/eslint-config": "^2.0.0",
        "@nuxtjs/eslint-module": "^1.0.0",
        "@nuxtjs/moment": "^1.6.1",
        "@nuxtjs/vuetify": "^1.0.0",
        "babel-eslint": "^10.0.1",
        "eslint": "^6.1.0",
        "eslint-plugin-nuxt": ">=0.4.2"
    },

My multistage Dockerfile:

# build_or_develop
FROM node:14-bullseye as build_or_develop

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
ENV NUXT_HOST=0.0.0.0
ENV NPM_CONFIG_PRODUCTION=false

RUN mkdir -p /home/node/nuxt/app && \
    chown -R node:node /home/node/nuxt

USER node
WORKDIR /home/node/nuxt

COPY ./package.json ./yarn.lock ./
RUN yarn install
ENV PATH /home/node/nuxt/node_modules/.bin:$PATH

WORKDIR /home/node/nuxt/app
EXPOSE 3000
CMD ["yarn", "dev"]

# production
FROM node:14-bullseye

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
ENV NUXT_HOST=0.0.0.0

RUN mkdir -p /home/node/nuxt/app && \
    chown -R node:node /home/node/nuxt

USER node
WORKDIR /home/node/nuxt

COPY --from=build_or_develop /home/node/nuxt/node_modules ./node_modules
ENV PATH /home/node/nuxt/node_modules/.bin:$PATH

WORKDIR /home/node/nuxt/app
COPY ./ .
RUN yarn build
EXPOSE 3000
CMD ["yarn", "start"]

SerDroide avatar Oct 11 '22 09:10 SerDroide

I'm seeing this problem in vite+typescript-based vuetify 3 project. I'm using latest vue and vuetify. Also vite adds vuetify to dependencies section, not devDependencies, and tsconfig.json does contain "types": ["vuetify"] entry in it, but VSCode keeps complaining about it:

Cannot find module 'vuetify/lib/util/colors' or its corresponding type declarations.

Interestingly, colors.orange.base work correctly in my project.

Shujee avatar Jun 08 '23 04:06 Shujee

+1 to @Shujee comment. I have the same setup vite, TS, vue3, vuetify3, and I'm seeing the same behavior. I also have vuetify added to the TSConfig types array.

TS complains about the import path, but all of the colors resolve.

agersea avatar Jul 12 '23 21:07 agersea