antfu-collective / vite-ssg

Static site generation for Vue 3 on Vite
MIT License
1.32k stars 136 forks source link

Can't build when use primevue #374

Open fernanduandrade opened 1 year ago

fernanduandrade commented 1 year ago

Describe the bug

Hello guys, I'm currently facing a problem where I installed primevue for my project and I'm unable to create the build when I run vite-ssg build it gives the following error bellow. Unfortunately I didn't find a similiar problem searching in forums and I also tried adding in my vite.config.ts in the ssrOptions the esm formart, but it didn't work. Does anyone has any ideia how could I solve this? Screenshot from 2023-09-28 07-39-44

Reproduction

Add primevue in the vite project, when run the build with vite-ssg it thorws the error

System Info

node:7166) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)

[vite-ssg] An internal error occurred.
[vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues
/home/fernando/Desktop/my-project/node_modules/primevue/config/config.esm.js:1
import { FilterMatchMode } from 'primevue/api';
^^^^^^

SyntaxError: Cannot use import statement outside a module

Used Package Manager

npm

Validations

anthopit commented 11 months ago

Same error! Have you found a solution?

fernanduandrade commented 11 months ago

Same error! Have you found a solution?

no solution yet, still searching

userquin commented 11 months ago

try adding these aliases:


// vite.config.ts/vite.config.js
  resolve: {
    alias: {
      'primevue/config': 'primevue/config/config.cjs.js',
      'primevue/api': 'primevue/api/api.cjs.js',
    }
  },
fernanduandrade commented 10 months ago

try adding these aliases:

// vite.config.ts/vite.config.js
  resolve: {
    alias: {
      'primevue/config': 'primevue/config/config.cjs.js',
      'primevue/api': 'primevue/api/api.cjs.js',
    }
  },

almost worked, but im facing a different problems now with the icons

ctd1500 commented 8 months ago

This is the workaround I figured out for a working vite.config

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import resolve from "@rollup/plugin-node-resolve";

const customResolver = resolve({
    extensions: [".esm.js", ".css", ".scss"]
});

export default defineConfig({
  plugins: [
    vue(),
  ],
  ssgOptions: {
    script: "async",
    formatting: "prettify",
  },
  resolve: {
    alias: [
      {
        find: "primevue",
        customResolver: customResolver,
        replacement: function(alias) {
          return alias;
        }
      }
    ]
  },
});