keithamus / postcss-hash

PostCSS plugin to replace output file names with HASH algorithms (md5, sha256, sha512, etc) and string length of your choice - for cache busting
MIT License
28 stars 8 forks source link

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string #8

Open simonh1000 opened 4 years ago

simonh1000 commented 4 years ago

I'm having trouble with my script. I have

// postcss.config.js
const purgecss = require("@fullhuman/postcss-purgecss")({
    // Specify the paths to all of the template files in your project
    content: ["./themes/losvast20/**/*.ejs"],

    // Include any special characters you're using in this regular expression
    defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
});

const nano = require("cssnano")({
    preset: "default"
});

const hash = require("postcss-hash")({
    algorithm: "sha256",
    trim: 20,
    manifest: "./manifest.json"
});

console.log("*******", process.env.NODE_ENV);
process.env.NODE_ENV = "production";

module.exports = {
    from: undefined,
    plugins: [
        require("postcss-nested"),
        require("postcss-color-function"),
        require("tailwindcss"),
        ...(process.env.NODE_ENV === "production" ? [purgecss, nano, hash] : [])
    ]
};

It worked up to the point that I added hashing.

At that point I got an error

ERROR Asset render failed: css/style.css
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:125:11)
    at Object.dirname (path.js:1260:5)
    at Object.rename (/Users/code/clients/losvast/node_modules/postcss-hash/utils.js:27:19)
    at /Users/code/clients/losvast/node_modules/postcss-hash/index.js:23:32

I'm completely new to postcss and am using it in this project to become more familiar

kwo commented 3 years ago

I'm having the same issue. Has there been a workaround for this?

kwisatz commented 9 months ago

I'm thinking this might be the same problem as #5. I also have no luck making this work. Applying the check from #5 will just not create any hashed file for me.

My postcss.config.cjs:

module.exports = {
    plugins: [
      require('postcss-import'),
      require('tailwindcss/nesting'),
      require("stylelint"),
      require('tailwindcss'),
      require('autoprefixer'),
      require('postcss-calc'),
      ...(process.env.JEKYLL_ENV == 'production'
        ? [
          require('cssnano')({ preset: 'default' }),
          // Cannot make this work, see https://github.com/keithamus/postcss-hash/issues/5
          // and https://github.com/keithamus/postcss-hash/issues/8
          // require('postcss-hash')({ algorithm: 'sha256' })
        ]
        : []
      )
    ]
  }