aklinker1 / vite-plugin-web-extension

Vite plugin for developing Chrome/Web Extensions
https://vite-plugin-web-extension.aklinker1.io/
MIT License
537 stars 46 forks source link

Crash when json.schemastore.org responds with HTTP Error #182

Closed HotariTobu closed 4 months ago

HotariTobu commented 4 months ago

Summary

The build step crashed when I passed transformManifest as an option of webExtension and https://json.schemastore.org/chrome-manifest returned HTTP Error 503.

無題

The error log:

...
vite v5.1.0 building for development...
✓ 1 modules transformed.
dist/src/index.css  26.42 kB │ gzip: 4.85 kB
✓ built in 186ms
undefined:1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
^

SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (file:///path/to/project/node_modules/.pnpm/vite-plugin-web-extension@4.1.1/node_modules/vite-plugin-web-extension/dist/index.js:949:20)
    at IncomingMessage.emit (node:events:530:35)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.11.0

The code near vite-plugin-web-extension/dist/index.js:949:20:

...
async function loadSchema() {
    if (schema != null)
      return;
    logger.verbose(`Loading JSON schema from ${SCHEMA_URL.href}...`);
    schema = await get(SCHEMA_URL.href);
  }
  function get(url) {
    return new Promise((res, rej) => {
      https.get(url, (response) => {
        let responseBody = "";
        response.on("data", (chunk) => {
          responseBody += chunk;
        });
        response.on("end", () => {
          res(JSON.parse(responseBody));      // <- 949
        });
      }).on("error", (err) => rej(err));
    });
  }
  return async (manifest) => {
    if (schema == null && await isOffline())
      return logger.warn(
        "Cannot connect to json.schemastore.org, skipping validation"
      );
    logger.verbose(`Validating manifest...`);
    if (manifest == null)
      throw Error(`Manifest cannot be ${manifest}`);
    await loadSchema();
...

Environment

$ npx envinfo --system --browsers --binaries --npmPackages vite,vite-plugin-web-extension

  System:
    OS: Windows 11 10.0.22631
    CPU: (6) x64 AMD Ryzen 5 3500 6-Core Processor
    Memory: 15.06 GB / 31.92 GB
  Binaries:
    Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.4.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.15.4 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (122.0.2365.66)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    vite: ^5.0.0 => 5.1.0
    vite-plugin-web-extension: ^4.1.1 => 4.1.1
surtic86 commented 4 months ago

Yes get the same error since today.

Workaround: Kill your Internet

aklinker1 commented 4 months ago

Quick fix released in 4.1.2