11ty / eleventy-plugin-vite

A plugin to use Vite with Eleventy
140 stars 10 forks source link

Eleventy constructor, Vitest, Invalid URL `about:blank` #25

Closed pauleveritt closed 5 months ago

pauleveritt commented 1 year ago

Big fan, using this this on an important project. TS/TSX and lots of Vitest.

I'd like to write kind of an E2E test without going to Playwright, using a style like this test in Eleventy. In that, Zach calls the Eleventy constructor himself and uses .toJSON to get rendered results. I had to do some config work to skip loading eleventy.config.js (due to require and script: "module" in package.json.)

When I get to EleventyVite:3 and const { createServer: createViteServer, build: buildVite } = require("vite"); ... I ultimate get this traceback:

TypeError: Invalid URL
    at new NodeError (node:internal/errors:393:5)
    at URL.onParseError (node:internal/url:565:9)
    at new URL (node:internal/url:645:5)
    at Object.<anonymous> (/Users/pauleveritt/WebstormProjects/g3-tsx/node_modules/@11ty/eleventy-plugin-vite/node_modules/vite/dist/node-cjs/publicUtils.cjs:39:175)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)

Here's the line it is failing on:

const VITE_PACKAGE_DIR = path$3.resolve(
// import.meta.url is `dist/node/constants.js` after bundle
node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))), '../../..');

It is because document.baseURI is about:blank (I believe.)

KiwiKilian commented 5 months ago

I guess this was part of your creation of eleventy-tsx? I see you are now using tsx because you never came around this blocker? Anything we could/should do about it regarding this plugin?

pauleveritt commented 5 months ago

Hi KiwiKilian thanks for asking. It's true, we are using using tsx for the main part of our work, but we're also still using the Vite plugin for some other parts.

KiwiKilian commented 5 months ago

So is the problem still persistent? Is there still a reproduction of this bug somewhere to be found?

pauleveritt commented 5 months ago

I think this can be closed.