nuxt.jsserverless-frameworkaws-serverlesscss-purge

Nuxt deploy with AWS lambda serverless - Internal server error - CouldWatch: Cannot find module 'nuxt-purgecss'


I'm trying to deploy my nuxt app with serverless but get the error "Cannot find module 'nuxt-purgecss'".

Any idea what could be the fix?

Below my nuxt.config.js

module.exports = {
  mode: "universal",
  /*
   ** Headers of the page
   */
  head: {
    title: process.env.APP_NAME,
    meta: [
      { charset: "utf-8" },
      { name: "viewport", content: "width=device-width, initial-scale=1" },
      {
        hid: "description",
        name: "description",
        content: process.env.npm_package_description || ""
      }
    ],
    link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }]
  },
  /*
   ** Customize the progress-bar color
   */
  loading: { color: "#fff" },
  /*
   ** Global CSS
   */
  css: ["~/assets/sass/tailwind.sass"],
  /*
   ** Plugins to load before mounting the App
   */
  plugins: [
    "./plugins/global.js",
    "./plugins/mixins/responsive.js",
    "./plugins/sbkl-client.js"
  ],
  /*
   ** Nuxt.js dev-modules
   */
  buildModules: [],
  /*
   ** Nuxt.js modules
   */
  modules: [
    "@nuxtjs/axios",
    "@nuxtjs/dotenv",
    "@nuxtjs/auth",
    "portal-vue/nuxt",
    "nuxt-purgecss"
  ],
  /*
   ** Axios module configuration
   ** See https://axios.nuxtjs.org/options
   */
  axios: {
    baseURL: process.env.URL + "/api"
  },
  /*
   ** Build configuration
   */
  build: {
    /*
     ** You can extend webpack config here
     */
    extractCSS: true,
    postcss: {
      plugins: {
        tailwindcss: path.resolve(__dirname, "./tailwind.config.js")
      }
    },
    transpile: ["sbkl-client"],
    extend(config, ctx) {}
  },
  purgeCSS: {
    mode: "postcss",
    paths: ["node_modules/sbkl-client/**/*.vue", "admin.config.js"]
  }
};

My package.json:

{
  "dependencies": {
    "@nuxtjs/auth": "^4.9.0",
    "@nuxtjs/axios": "^5.3.6",
    "@nuxtjs/dotenv": "^1.4.0",
    "@popperjs/core": "^2.1.0",
    "nuxt-start": "^2.11.0",
    "portal-vue": "^2.1.7",
    "sbkl-client": "^1.0.1",
    "serverless-nuxt": "^1.1.1"
  },
  "devDependencies": {
    "@tailwindcss/ui": "^0.1.3",
    "node-sass": "^4.13.1",
    "nuxt": "^2.11.0",
    "nuxt-purgecss": "^0.2.1",
    "sass-loader": "^8.0.2",
    "serverless-domain-manager": "^3.3.1",
    "serverless-nuxt-plugin": "^1.1.0",
    "tailwindcss": "^1.2.0"
  }
}

Solution

  • Just needed to move nuxt-purgecss from my devDependencies to my dependencies since it is needed for the build.

    {
      "dependencies": {
        "@nuxtjs/auth": "^4.9.0",
        "@nuxtjs/axios": "^5.3.6",
        "@nuxtjs/dotenv": "^1.4.0",
        "@popperjs/core": "^2.1.0",
        "nuxt-purgecss": "^0.2.1",
        "nuxt-start": "^2.11.0",
        "portal-vue": "^2.1.7",
        "sbkl-client": "^1.0.1",
        "serverless-nuxt": "^1.1.1"
      },
      "devDependencies": {
        "@tailwindcss/ui": "^0.1.3",
        "node-sass": "^4.13.1",
        "nuxt": "^2.11.0",
        "sass-loader": "^8.0.2",
        "serverless-domain-manager": "^3.3.1",
        "serverless-nuxt-plugin": "^1.1.0",
        "tailwindcss": "^1.2.0"
      }
    }