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

Error plugin[name] is not a function encountered when building with Vite/Vue3/Pug3 #1

Closed
Tempystral opened this issue May 25, 2022 · 9 comments

Comments

@Tempystral
Copy link

Hi, I'm having trouble getting this plugin to work. I'm packaging my app with Vite and followed the instructions on how to add the plugin. Whenever I try to run the dev server or build, I get the error that "plugin[name]" is not a function, and I confess I'm too inexperienced with the platform to say exactly why.

My Vite config is very simple, not too different from the example except that I'm using Typescript and ES Modules, neither of which seem like they should interfere with this.

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import * as vuePugPlugin from "vue-pug-plugin";

export default defineConfig({
  root: "./src",
  build: {
    outDir: "../dist",
    emptyOutDir: true
  },
  plugins: [
    vue({
      template: {
        preprocessOptions: {
          plugins: [{
              preCodeGen: vuePugPlugin
            }]
        }
      }
    })
  ]
});

The error I get is the following:

[plugin:vite:vue] plugin[name] is not a function

/src/components/Expansion.vue
    at /node_modules/pug/lib/index.js:45:39
    at Array.reduce (<anonymous>)
    at applyPlugins (/node_modules/pug/lib/index.js:44:18)
    at compileBody (/node_modules/pug/lib/index.js:198:9)
    at Object.exports.compile (/node_modules/pug/lib/index.js:269:16)
    at /node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:2317:58
    at /node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:1439:5
    at new Promise (<anonymous>)
    at promisify (/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:1432:10)
    at Function.exports.pug.render (/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:2302:10

Sorry, I know this is an old project and I understand if it's not being supported, but I would appreciate any insight on this issue.

@matthewjumpsoffbuildings
Copy link
Owner

The project is being supported, I still use it actively. This is likely due to the fact the package doesnt export an ES module, only CommonJS. I will investigate

@matthewjumpsoffbuildings
Copy link
Owner

matthewjumpsoffbuildings commented May 26, 2022

@Tempystral Okay it turns out you are just using the import statement incorrectly. The following should do the trick:

import vuePugPlugin from 'vue-pug-plugin'

@Tempystral
Copy link
Author

Interesting, I had tried that as well and it didn't seem to be working, but I will investigate further on my end. I'll update later if I have more information -- thanks!

@matthewjumpsoffbuildings
Copy link
Owner

Im using it with that syntax in a vite/vue3 project successfully. ES6/TS projects should be able to import CommonJS modules default exports like that with no issues

@matthewjumpsoffbuildings
Copy link
Owner

I have updated my test project and am now seeing the same issue. Perhaps something has changed in vite or pug packages since last time I tested it.

@matthewjumpsoffbuildings
Copy link
Owner

matthewjumpsoffbuildings commented May 26, 2022

Actually nevermind @Tempystral - it was due to me updating to version 2.0.0 of this plugin, in which I changed the syntax.

I would recommend you doing the same, updating to version 2.0.0 changing your code to the following

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vuePugPlugin from "vue-pug-plugin";

export default defineConfig({
  root: "./src",
  build: {
    outDir: "../dist",
    emptyOutDir: true
  },
  plugins: [
    vue({
      template: {
        preprocessOptions: {
          plugins: [
            vuePugPlugin,
          ]
        }
      }
    })
  ]
});

@Tempystral
Copy link
Author

I'll give that a try, thanks. I'll let you know the result when I have a moment to sit down and test.

@Tempystral
Copy link
Author

I can confirm it works, just had to make sure I was installing the new version. Thanks a million.

@matthewjumpsoffbuildings
Copy link
Owner

@Tempystral you're welcome

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