Skip to content

html-minifier library causes adapter-node to break #8049

@lubiah

Description

@lubiah

Describe the bug

The docs provide a way which you can use to minify the HTML that is rendered. However, if you use that method, it breaks adapter-node.

This is the error output

    require.resolve("../lib/utils.js"),
            ^

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Projects\kudadam\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///C:/Projects/kudadam/build/server/chunks/server-b56e4b54.js:24606:6
    at file:///C:/Projects/kudadam/build/server/chunks/server-b56e4b54.js:24713:3
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async Server.init (file:///C:/Projects/kudadam/build/server/index.js:3183:22)
    at async file:///C:/Projects/kudadam/build/handler.js:18886:1

Reproduction

I have made a repo with the bug: Repo Link

Logs

require.resolve("../lib/utils.js"),
            ^

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Projects\kudadam\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///C:/Projects/kudadam/build/server/chunks/server-b56e4b54.js:24606:6
    at file:///C:/Projects/kudadam/build/server/chunks/server-b56e4b54.js:24713:3
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async Server.init (file:///C:/Projects/kudadam/build/server/index.js:3183:22)
    at async file:///C:/Projects/kudadam/build/handler.js:18886:1

System Info

$ pnpx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
.../Local/pnpm/store/v3/tmp/dlx-3476     |   +1 +
.../Local/pnpm/store/v3/tmp/dlx-3476     | Progress: resolved 1, reused 1, downloaded 0, added 1, done

  System:
    OS: Windows 10 10.0.19044
    CPU: (4) x64 Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz
    Memory: 860.15 MB / 7.91 GB
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (108.0.1462.42)
  npmPackages:
    @sveltejs/adapter-node: 1.0.0-next.104 => 1.0.0-next.104
    @sveltejs/kit: next => 1.0.0-next.581
    svelte: ^3.54.0 => 3.54.0
    vite: ^4.0.0 => 4.0.0

Severity

blocking an upgrade

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions