Jervis2049 / vite-plugin-crx-mv3

Build a Chrome Extension with Vite⚡
201 stars 30 forks source link

Support new versions of vite(typescript) with acorn library exporting #34

Closed vladislavkovaliov closed 9 months ago

vladislavkovaliov commented 9 months ago

It looks that it isn't compatible with last version of vite.

It happens when I try to start project. It occurs inside vite.config.ts I took look the examples for react but I have got error message below:

failed to load config from /Users/vkovaliov/temp/github-exts/vite.config.ts
error during build:
file:///Users/vkovaliov/temp/github-exts/node_modules/vite-plugin-crx-mv3/dist/index.mjs:16
import acorn from "acorn";
       ^^^^^
SyntaxError: The requested module 'acorn' does not provide an export named 'default'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:122:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:188:5)

Configs: node: v20.2.0 vite: ^5.0.0 typescript: ^5.2.2

Vite config:

import { defineConfig } from "vite";
import { resolve } from "path";
import react from "@vitejs/plugin-react";
import crx from 'vite-plugin-crx-mv3'

// TODO: makes dedicated enrties for popup and content script
// https://vitejs.dev/config/
export default defineConfig({
    build: {
        rollupOptions: {
          input: {
            contentScript: resolve(__dirname, "contentScript.html"),
            popup: resolve(__dirname, "popup.html"),
            main: "src/main.tsx",
            mainPopup: "src/popup/mainPopup.tsx",
          },
        },
      },
    plugins: [react(), crx({
      manifest: './src/manifest.json',
    }),],
});

Typescript config:

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": false,
    "skipLibCheck": false,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": false,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

Any advices or way to manage it, please?

Might be it possible to update for repo according to ne versions of vite and typescript?

vladislavkovaliov commented 9 months ago

Duplication https://github.com/Jervis2049/vite-plugin-crx-mv3/issues/32