Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite build crashes due cryptic issues with path separators #886

Closed
mcunha opened this issue May 16, 2023 · 5 comments
Closed

vite build crashes due cryptic issues with path separators #886

mcunha opened this issue May 16, 2023 · 5 comments
Labels

Comments

@mcunha
Copy link

mcunha commented May 16, 2023

Description

I'm a node/react noob and made a react app using pnpm and Vite - vite dev works fine. Tried to deploy on vercel which uses vite build. It's been a rabbit hole of troubleshooting since then but at the moment my "probably-not-the-right-vite-config-just-yet" generates the stack trace below with no helpful error message related to which path is "bad" nor what's "bad about it".

I fully accept this is likely misconfiguration on my side. I've read the guidelines and rules; submitting because you asked for stacktrace submissions that are unhelpful. I've also been trying to solve this for a couple of hours now and will continue trying.

Hope this helps improve the codebase!

vite.config.ts:

import {defineConfig} from "vite";
import vercel from "vite-plugin-vercel";
import ssr from "vite-plugin-ssr/plugin";
import vercelSsr from "@magne4000/vite-plugin-vercel-ssr";
import react from "@vitejs/plugin-react-swc";
import {glob} from "glob";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig(async () => {
  return {
    plugins: [react(), ssr({ prerender: true }), vercel(), vercelSsr()],
    vercel: { expiration: 25, server: { port: 3000 } },
    //    root: "src",
    root: path.resolve(__dirname, "src"),
    build: {
      outDir: path.resolve(__dirname, "dist"),
      rollupOptions: {
        input: glob.sync(path.resolve(__dirname, "src", "*.html")),
      },
    },
  };
});

Stacktrace:

Error: [vite-plugin-ssr@0.4.123][Bug] You stumbled upon a bug in vite-plugin-ssr's source code. Go to https://github.com/brillout/vite-plugin-ssr/issues/new and copy-paste this error. (The error's stack trace is usually enough to fix the problem). A maintainer will fix the bug (usually under 24 hours). Don't hesitate to reach out as it makes vite-plugin-ssr more robust.
--
03:16:22.088 | at removePathSeperators (/vercel/path0/node_modules/.pnpm/vite-plugin-ssr@0.4.123_vite@4.3.2/node_modules/vite-plugin-ssr/dist/cjs/node/plugin/plugins/distFileNames.js:93:24)
03:16:22.088 | at getEntryFileName (/vercel/path0/node_modules/.pnpm/vite-plugin-ssr@0.4.123_vite@4.3.2/node_modules/vite-plugin-ssr/dist/cjs/node/plugin/plugins/distFileNames.js:83:12)
03:16:22.088 | at rollupOutput.entryFileNames (/vercel/path0/node_modules/.pnpm/vite-plugin-ssr@0.4.123_vite@4.3.2/node_modules/vite-plugin-ssr/dist/cjs/node/plugin/plugins/distFileNames.js:22:66)
03:16:22.089 | at Chunk.getPreliminaryFileName (file:///vercel/.local/share/pnpm/store/v3/tmp/dlx-229/node_modules/.pnpm/rollup@3.21.7/node_modules/rollup/dist/es/shared/node-entry.js:15639:74)
03:16:22.089 | at reserveEntryChunksInBundle (file:///vercel/.local/share/pnpm/store/v3/tmp/dlx-229/node_modules/.pnpm/rollup@3.21.7/node_modules/rollup/dist/es/shared/node-entry.js:17326:19)
03:16:22.089 | at renderChunks (file:///vercel/.local/share/pnpm/store/v3/tmp/dlx-229/node_modules/.pnpm/rollup@3.21.7/node_modules/rollup/dist/es/shared/node-entry.js:17312:5)
03:16:22.089 | at Bundle.generate (file:///vercel/.local/share/pnpm/store/v3/tmp/dlx-229/node_modules/.pnpm/rollup@3.21.7/node_modules/rollup/dist/es/shared/node-entry.js:17535:19)
03:16:22.089 | at async file:///vercel/.local/share/pnpm/store/v3/tmp/dlx-229/node_modules/.pnpm/rollup@3.21.7/node_modules/rollup/dist/es/shared/node-entry.js:25827:27
03:16:22.089 | at async catchUnfinishedHookActions (file:///vercel/.local/share/pnpm/store/v3/tmp/dlx-229/node_modules/.pnpm/rollup@3.21.7/node_modules/rollup/dist/es/shared/node-entry.js:24914:20)
03:16:22.089 | at async build (file:///vercel/.local/share/pnpm/store/v3/tmp/dlx-229/node_modules/.pnpm/vite@4.3.6/node_modules/vite/dist/node/chunks/dep-a04f07ec.js:46459:22)
03:16:22.089 | at async CAC.<anonymous> (file:///vercel/.local/share/pnpm/store/v3/tmp/dlx-229/node_modules/.pnpm/vite@4.3.6/node_modules/vite/dist/node/cli.js:812:9)
03:16:22.107 | ERROR  Command failed with exit code 1: vite build
@brillout
Copy link
Member

Thanks for the bug report; don't hesitate to reach out when you hit such error.

Insert the following before line 93 of /vercel/path0/node_modules/.pnpm/vite-plugin-ssr@0.4.123_vite@4.3.2/node_modules/vite-plugin-ssr/dist/cjs/node/plugin/plugins/distFileNames.js:

function removePathSeperators(name) {
    (0, utils_1.assertPosixPath)(name);
+   console.log('name', name);
    (0, utils_1.assert)(!name.startsWith('/'));
    const entryDir = 'entries/';

What's the log result?

@mcunha
Copy link
Author

mcunha commented May 16, 2023

Thanks for looking into it. Since this happened inside a Vercel build, and I'm not enough of an expert to know how to monkey patch node_modules during a remote build with them I'm unable to share the result.

I have however spent some time trying to repro this locally today and I've now succeeded - in the process I think I solved my mistake. I need to take a break for dinner and family time but I'll follow up later this evening with two or three repro scenarios. Stay tuned :)

@brillout
Copy link
Member

👍 Looking forward to these repros.

@mcunha
Copy link
Author

mcunha commented May 16, 2023

Context

Item Value
OS Name Microsoft Windows 11 Pro
OS Version 10.0.22621 N/A Build 22621
node --version 18.16.0
vite 4.3.6

Scenario #1

  • Run the following
pnpm create vite@latest repro-app-24796 --template react-swc-ts
cd repro-app-24796
pnpm install
pnpm add -D vite-plugin-ssr
  • Up until here vite should have no problems running vite dev|preview|build
  • Lets edit vite.config.ts and add the following content to it
// The only real changes to this file from ther defaults is 
// the import ssr line and the ssr() invocation
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import ssr from "vite-plugin-ssr/plugin"
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(), ssr({prerender: true})],
})
  • Verify vite dev works
vite dev

#  VITE v4.3.6  ready in 1196 ms
#
#  ➜  Local:   http://localhost:3000/
#  ➜  Network: use --host to expose
#  ➜  press h to show help
  • Verify vite build now breaks
vite build

# vite v4.3.6 building for production...
# ✓ 0 modules transformed.
# ✓ built in 10ms
# You must supply options.input to rollup
# error during build:
# Error: You must supply options.input to rollup
#     at Graph.generateModuleGraph (file:///C:/Users/Rocket/AppData/Roaming/npm/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24795:19)
#     at async Graph.build (file:///C:/Users/Rocket/AppData/Roaming/npm/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24740:9)
#     at async file:///C:/Users/Rocket/AppData/Roaming/npm/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:25761:13
#     at async catchUnfinishedHookActions (file:///C:/Users/Rocket/AppData/Roaming/npm/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24914:20)
#     at async rollupInternal (file:///C:/Users/Rocket/AppData/Roaming/npm/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:25756:5)
#     at async build (file:///C:/Users/Rocket/AppData/Roaming/npm/node_modules/vite/dist/node/chunks/dep-a04f07ec.js:46453:18)
#     at async CAC.<anonymous> (file:///C:/Users/Rocket/AppData/Roaming/npm/node_modules/vite/dist/node/cli.js:812:9)
  • It's very possible as a noob I failed to understand the impact of enabling ssr - however to an unsupecting user trying to learn the plugin it's unclear what just happened - options.input was not supplied or needed for vite dev. If the error message is technically correct, a more useful error message pointing user to somewhere in docs with more actionable advice would be helpful so users can dig themselves out of the hole they made.

NOTE: This isn't the same stack trace as my original submission - that's because this is the original issue that started my attempts to configure the plugin which eventually ended with the error message seen at the start of this. I'll add more details on Scenario #2 tomorrow.

@brillout
Copy link
Member

Done.

~/tmp/repro-app-24796 (main*) pnpm run build

> repro-app-24796@0.0.0 build /home/rom/tmp/repro-app-24796
> tsc && vite build

error during build:
Error: [vite-plugin-ssr@0.4.123][Wrong Usage] At least one page should be defined, see https://vite-plugin-ssr.com/add
    at getEntries (/home/rom/code/vite-plugin-ssr/vite-plugin-ssr/dist/cjs/node/plugin/plugins/buildConfig.js:43:29)
    at async configResolved (/home/rom/code/vite-plugin-ssr/vite-plugin-ssr/dist/cjs/node/plugin/plugins/buildConfig.js:17:29)
    at async Promise.all (index 11)
    at async resolveConfig (file:///home/rom/tmp/repro-app-24796/node_modules/.pnpm/vite@4.3.2/node_modules/vite/dist/node/chunks/dep-7efa13d7.js:64190:5)
    at async build (file:///home/rom/tmp/repro-app-24796/node_modules/.pnpm/vite@4.3.2/node_modules/vite/dist/node/chunks/dep-7efa13d7.js:46244:20)
    at async CAC.<anonymous> (file:///home/rom/tmp/repro-app-24796/node_modules/.pnpm/vite@4.3.2/node_modules/vite/dist/node/cli.js:812:9)
 ELIFECYCLE  Command failed with exit code 1.
~/tmp/repro-app-24796 (main*) pnpm run build

> repro-app-24796@0.0.0 build /home/rom/tmp/repro-app-24796
> tsc && vite build

error during build:
Error: [vite-plugin-ssr@0.4.123][Wrong Usage] The entry /home/rom/tmp/repro-app-24796/index.html of config build.rollupOptions.input is an HTML entry which is forbidden when using vite-plugin-ssr, instead follow https://vite-plugin-ssr.com/add
    at assertRollupInput (/home/rom/code/vite-plugin-ssr/vite-plugin-ssr/dist/cjs/node/plugin/plugins/buildConfig.js:201:29)
    at configResolved (/home/rom/code/vite-plugin-ssr/vite-plugin-ssr/dist/cjs/node/plugin/plugins/commonConfig.js:20:49)
    at file:///home/rom/tmp/repro-app-24796/node_modules/.pnpm/vite@4.3.2/node_modules/vite/dist/node/chunks/dep-7efa13d7.js:64193:28
    at Array.map (<anonymous>)
    at resolveConfig (file:///home/rom/tmp/repro-app-24796/node_modules/.pnpm/vite@4.3.2/node_modules/vite/dist/node/chunks/dep-7efa13d7.js:64193:14)
    at async build (file:///home/rom/tmp/repro-app-24796/node_modules/.pnpm/vite@4.3.2/node_modules/vite/dist/node/chunks/dep-7efa13d7.js:46244:20)
    at async CAC.<anonymous> (file:///home/rom/tmp/repro-app-24796/node_modules/.pnpm/vite@4.3.2/node_modules/vite/dist/node/cli.js:812:9)
 ELIFECYCLE  Command failed with exit code 1.

Let me know if you run into any other paper cut like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants