nksaraf / vinxi

The Full Stack JavaScript SDK
https://vinxi.vercel.app
MIT License
1.33k stars 56 forks source link

Cannot start vinxi app that imports video.js #268

Closed knpwrs closed 3 months ago

knpwrs commented 3 months ago

Here is an example stackblitz based on an official vinxi example: https://stackblitz.com/edit/github-abrfac?file=app%2Fapp.tsx

Note that the video won't play there because of CORS, but the bug I'm experiencing with vinxi is still present.

When you run npm run dev (vinxi dev), video.js is able to load. However, when you run npm run build followed by npm start (vinxi build followed by vinxi start), the following is output to the console:

[10:52:59 PM]  ERROR  Cannot find module '/home/projects/github-abrfac/.output/server/node_modules/global/window' imported from /home/projects/github-abrfac/.output/server/index.mjs
Did you mean to import global/window.js?

  Did you mean to import global/window.js?
  at makeNodeErrorWithCode/< (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:36:4170)
  at defaultResolve/m</< (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:114:12002)
  at defaultResolve/m< (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:114:12159)
  at defaultResolve (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:114:12167)
  at nextHookFactory/< (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:248:2120)
  at resolve (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:248:7556)
  at getModuleJob (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:248:4387)
  at ModuleJob/this.linked</r< (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:181:932)
  at link (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:352:381670)
  at ModuleJob/this.linked< (https://githubabrfac-dkkx.w-corp-staticblitz.com/blitz.d0228c83.js:181:893) 

[10:52:59 PM]  ERROR  Cannot find module '/home/projects/github-abrfac/.output/server/node_modules/global/window' imported from /home/projects/github-abrfac/.output/server/index.mjs
Did you mean to import global/window.js?

I am encountering this issue on a project that I am porting from an old (pre-vinxi) version of solid start -- video.js works fine in vite, just not in built vinxi apps.

This is the output of npm why global:

global@4.4.0
node_modules/global
  global@"^4.4.0" from aes-decrypter@4.0.1
  node_modules/aes-decrypter
    aes-decrypter@"^4.0.1" from video.js@8.10.0
    node_modules/video.js
      video.js@"^8.10.0" from the root project
      peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
      node_modules/videojs-contrib-quality-levels
        videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
      video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
    aes-decrypter@"4.0.1" from @videojs/http-streaming@3.10.0
    node_modules/@videojs/http-streaming
      @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"^4.4.0" from m3u8-parser@7.1.0
  node_modules/m3u8-parser
    m3u8-parser@"^7.1.0" from video.js@8.10.0
    node_modules/video.js
      video.js@"^8.10.0" from the root project
      peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
      node_modules/videojs-contrib-quality-levels
        videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
      video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
    m3u8-parser@"^7.1.0" from @videojs/http-streaming@3.10.0
    node_modules/@videojs/http-streaming
      @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"^4.4.0" from mpd-parser@1.3.0
  node_modules/mpd-parser
    mpd-parser@"^1.2.2" from video.js@8.10.0
    node_modules/video.js
      video.js@"^8.10.0" from the root project
      peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
      node_modules/videojs-contrib-quality-levels
        videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
      video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
    mpd-parser@"^1.3.0" from @videojs/http-streaming@3.10.0
    node_modules/@videojs/http-streaming
      @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"^4.4.0" from mux.js@7.0.3
  node_modules/mux.js
    mux.js@"^7.0.1" from video.js@8.10.0
    node_modules/video.js
      video.js@"^8.10.0" from the root project
      peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
      node_modules/videojs-contrib-quality-levels
        videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
      video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"4.4.0" from video.js@8.10.0
  node_modules/video.js
    video.js@"^8.10.0" from the root project
    peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
    node_modules/videojs-contrib-quality-levels
      videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
    video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
    node_modules/@videojs/http-streaming
      @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"^4.4.0" from videojs-contrib-quality-levels@4.0.0
  node_modules/videojs-contrib-quality-levels
    videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
  global@"^4.3.1" from videojs-vtt.js@0.15.5
  node_modules/videojs-vtt.js
    videojs-vtt.js@"0.15.5" from video.js@8.10.0
    node_modules/video.js
      video.js@"^8.10.0" from the root project
      peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
      node_modules/videojs-contrib-quality-levels
        videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
      video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"^4.4.0" from @videojs/http-streaming@3.10.0
  node_modules/@videojs/http-streaming
    @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"^4.4.0" from @videojs/vhs-utils@4.0.0
  node_modules/@videojs/vhs-utils
    @videojs/vhs-utils@"^4.0.0" from mpd-parser@1.3.0
    node_modules/mpd-parser
      mpd-parser@"^1.2.2" from video.js@8.10.0
      node_modules/video.js
        video.js@"^8.10.0" from the root project
        peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
        node_modules/videojs-contrib-quality-levels
          videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
        video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
        node_modules/@videojs/http-streaming
          @videojs/http-streaming@"3.10.0" from video.js@8.10.0
      mpd-parser@"^1.3.0" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
    @videojs/vhs-utils@"^4.0.0" from video.js@8.10.0
    node_modules/video.js
      video.js@"^8.10.0" from the root project
      peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
      node_modules/videojs-contrib-quality-levels
        videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
      video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
    @videojs/vhs-utils@"4.0.0" from @videojs/http-streaming@3.10.0
    node_modules/@videojs/http-streaming
      @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"~4.4.0" from @videojs/xhr@2.6.0
  node_modules/@videojs/xhr
    @videojs/xhr@"2.6.0" from video.js@8.10.0
    node_modules/video.js
      video.js@"^8.10.0" from the root project
      peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
      node_modules/videojs-contrib-quality-levels
        videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
      video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"^4.4.0" from mux.js@7.0.2
  node_modules/@videojs/http-streaming/node_modules/mux.js
    mux.js@"7.0.2" from @videojs/http-streaming@3.10.0
    node_modules/@videojs/http-streaming
      @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"^4.4.0" from @videojs/vhs-utils@3.0.5
  node_modules/aes-decrypter/node_modules/@videojs/vhs-utils
    @videojs/vhs-utils@"^3.0.5" from aes-decrypter@4.0.1
    node_modules/aes-decrypter
      aes-decrypter@"^4.0.1" from video.js@8.10.0
      node_modules/video.js
        video.js@"^8.10.0" from the root project
        peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
        node_modules/videojs-contrib-quality-levels
          videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
        video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
        node_modules/@videojs/http-streaming
          @videojs/http-streaming@"3.10.0" from video.js@8.10.0
      aes-decrypter@"4.0.1" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
  global@"^4.4.0" from @videojs/vhs-utils@3.0.5
  node_modules/m3u8-parser/node_modules/@videojs/vhs-utils
    @videojs/vhs-utils@"^3.0.5" from m3u8-parser@7.1.0
    node_modules/m3u8-parser
      m3u8-parser@"^7.1.0" from video.js@8.10.0
      node_modules/video.js
        video.js@"^8.10.0" from the root project
        peer video.js@"^8" from videojs-contrib-quality-levels@4.0.0
        node_modules/videojs-contrib-quality-levels
          videojs-contrib-quality-levels@"4.0.0" from video.js@8.10.0
        video.js@"^7 || ^8" from @videojs/http-streaming@3.10.0
        node_modules/@videojs/http-streaming
          @videojs/http-streaming@"3.10.0" from video.js@8.10.0
      m3u8-parser@"^7.1.0" from @videojs/http-streaming@3.10.0
      node_modules/@videojs/http-streaming
        @videojs/http-streaming@"3.10.0" from video.js@8.10.0
nksaraf commented 3 months ago

i think video.js is a package that shouldn't come in the client. So make it a dynamic lazy import and use it inside a !isServer check.

import "./style.css";

import { isServer } from "solid-js/web";
import { onMount } from "solid-js";

export default function App({ assets, scripts }) {
  let videoEl: HTMLVideoElement;

  onMount(() => {
    if (!isServer) {
      import("video.js").then((mod) => {
        let videojs = mod.default;
        videojs(videoEl, {
          controls: true,
        });
      });
    }
  });
  return (
    <html lang="en">
      <head>
        <link
          rel="icon"
          href={`${import.meta.env.SERVER_BASE_URL}/favicon.ico`}
        />
        {assets}
      </head>
      <body>
        <video ref={videoEl!} src="https://vjs.zencdn.net/v/oceans.mp4" />
        {scripts}
      </body>
    </html>
  );
}
knpwrs commented 3 months ago

That seems to have done the trick, thank you!