vite-plugin-html icon indicating copy to clipboard operation
vite-plugin-html copied to clipboard

ERROR [vite:resolve] id.startsWith is not a function

Open masx200 opened this issue 3 years ago • 1 comments

这样配置运行会出错

import { defineConfig } from "vite";
import { babel } from "@rollup/plugin-babel";
import { resolve } from "path";
const root = resolve(__dirname, "src");
import { createHtmlPlugin } from "vite-plugin-html";
export default defineConfig({
    esbuild: { drop: ["console", "debugger"] },
    root,
    plugins: [
        babel({
            exclude: [/node_modules/],
            babelHelpers: "bundled",
            configFile: resolve(__dirname, "babel.config.js"),
            extensions: [".ts", ".js"],
        }),
        createHtmlPlugin({
            minify: {
                removeAttributeQuotes: false,
                collapseWhitespace: true,
            },
         }),
    ].flat(),
    build: {
        minify: "terser",
        terserOptions: {
            compress: { drop_console: true, drop_debugger: true },
        },
        target: "es2015",
        rollupOptions: {
            plugins: [
               
            ].flat(),

            input: [
                resolve(root, "index.html"),
                resolve(root, "hieroglyphy-encoder.html"),
                resolve(
                    root,
                    "JSFuck---Write-any-JavaScript-with-6-Characters_-[]()!+.html"
                ),
                // resolve(root, "JSfuck-Decoder--and-hieroglyphy--decoder.html"),
            ],
        },
    },
});

错误的输出

vite build


vite v2.9.1 building for production...                                                                                       10:12:58
✓ 0 modules transformed.                                                                                                     10:12:59  

 ERROR  [vite:resolve] id.startsWith is not a function                                                                       10:12:59  


 ERROR  error during build:                                                                                                  10:12:59  
TypeError: id.startsWith is not a function
    at Object.resolveId (C:\Documents\GitHub\JSfuck-and-hieroglyphy-Decoder-and-ENCODER\node_modules\vite\dist\node\chunks\dep-611778e0.js:37781:20)
    at C:\Documents\GitHub\JSfuck-and-hieroglyphy-Decoder-and-ENCODER\node_modules\vite\node_modules\rollup\dist\shared\rollup.js:22810:37

这样配置可以正常运行

import { defineConfig } from "vite";
import { babel } from "@rollup/plugin-babel";
import { resolve } from "path";
const root = resolve(__dirname, "src");
import { createHtmlPlugin } from "vite-plugin-html";
export default defineConfig({
    esbuild: { drop: ["console", "debugger"] },
    root,
    plugins: [
        babel({
            exclude: [/node_modules/],
            babelHelpers: "bundled",
            configFile: resolve(__dirname, "babel.config.js"),
            extensions: [".ts", ".js"],
        }),
        // createHtmlPlugin({
        //     minify: {
        //         removeAttributeQuotes: false,
        //         collapseWhitespace: true,
        //     },
        // }),
    ].flat(),
    build: {
        minify: "terser",
        terserOptions: {
            compress: { drop_console: true, drop_debugger: true },
        },
        target: "es2015",
        rollupOptions: {
            plugins: [
                createHtmlPlugin({
                    minify: {
                        removeAttributeQuotes: false,
                        collapseWhitespace: true,
                    },
                }),
            ].flat(),

            input: [
                resolve(root, "index.html"),
                resolve(root, "hieroglyphy-encoder.html"),
                resolve(
                    root,
                    "JSFuck---Write-any-JavaScript-with-6-Characters_-[]()!+.html"
                ),
                // resolve(root, "JSfuck-Decoder--and-hieroglyphy--decoder.html"),
            ],
        },
    },
});

正常的输出

vite build


vite v2.9.1 building for production...                                                                        10:11:47
✓ 18 modules transformed.                                                                                     10:11:48

 WARN  warnings when minifying css:                                                                           10:11:48
▲ [WARNING] The "-" operator only works if there is whitespace on both sides

    <stdin>:85:20:
      85 │     width: calc(100%-40px);
         ╵                     ^



dist/JSFuck---Write-any-JavaScript-with-6-Characters_-[]()!+.html                  2.62 KiB                   10:11:49
dist/hieroglyphy-encoder.html                                                      2.44 KiB                   10:11:49
dist/index.html                                                                    2.56 KiB                   10:11:49
dist/assets/index.f1fe29ed.js                                                      2.16 KiB / gzip: 0.70 KiB  10:11:49
dist/assets/hieroglyphy-encoder.fd267c08.js                                        0.57 KiB / gzip: 0.34 KiB  10:11:49
dist/assets/JSFuck---Write-any-JavaScript-with-6-Characters_-__()!_.94f8ec31.js    0.54 KiB / gzip: 0.33 KiB  10:11:49
dist/assets/myfontandtextalign.0151629b.js                                         0.69 KiB / gzip: 0.39 KiB  10:11:49
dist/assets/hieroglyphy.acd64757.js                                                2.28 KiB / gzip: 0.79 KiB  10:11:49
dist/assets/jsfuck.0f418e9e.js                                                     3.70 KiB / gzip: 1.58 KiB  10:11:49
dist/assets/JSFuck---Write-any-JavaScript-with-6-Characters_-__()!_.19da34d4.css   0.28 KiB / gzip: 0.21 KiB  10:11:49
dist/assets/myfontandtextalign.0b7bedcc.css                                        0.17 KiB / gzip: 0.16 KiB  10:11:49
dist/assets/hieroglyphy-encoder.b117f5cb.css                                       1.38 KiB / gzip: 0.53 KiB  10:11:49
dist/assets/index.57c7e7b5.css

版本信息

 node -v  v16.14.2

 "vite": "^2.9.1",

        "vite-plugin-html": "^3.2.0"

masx200 avatar Apr 03 '22 02:04 masx200

I can confirm this. Maybe the structure changed?

Chris2011 avatar May 06 '22 21:05 Chris2011