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 + createFileUploadHandler: file uploading error #8961

Closed
romanpeganov opened this issue Mar 2, 2024 · 3 comments
Closed

Vite + createFileUploadHandler: file uploading error #8961

romanpeganov opened this issue Mar 2, 2024 · 3 comments

Comments

@romanpeganov
Copy link

Reproduction

Hello, I create a new project with Remix. Now I use the project development and building with Vite. Today I reached the file downloading feature. I do everything as usual, according to the instructions on the Remix.dev website. I did this earlier, with a remix development server and everything worked well.
But now, when I'm trying to upload the file, the vite-plugin-remix gives the error "ReferenceError: File is not defined". This happens because file "/node_modules/@remix-run/node/dist/upload/fileUploadHandler.js:143" contains class member creted from class "File". This member is not used. I just comment it and uploading was successful.
"File" is a class of a browser environment, so Vite knows nothing about it on the server. I ask you to fix this bug.

My project env is remix 2.8.0, with vite-plugin-remix and with typescript.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz   
    Memory: 8.89 GB / 15.95 GB
  Binaries:
    Node: 18.19.0 - C:\Program Files\nodejs\node.EXE        
    Yarn: 4.1.0 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 122.0.6261.94
    Edge: Spartan (44.19041.3636.0), Chromium (122.0.2365.59)
    Internet Explorer: 11.0.19041.3636
  npmPackages:
    @remix-run/dev: ^2.8.0 => 2.8.0
    @remix-run/node: ^2.8.0 => 2.8.0
    @remix-run/react: ^2.8.0 => 2.8.0
    @remix-run/serve: ^2.8.0 => 2.8.0
    @remix-run/testing: ^2.8.0 => 2.8.0
    vite: ^5.1.4 => 5.1.4

Used Package Manager

yarn

Expected Behavior

Uploading files with Vite and without error.

Actual Behavior

ReferenceError: File is not defined
at <instance_members_initializer> (W:\Projects\alab-remix-2\node_modules\@remix-run\node\dist\upload\fileUploadHandler.js:143:20)
at new NodeOnDiskFile (W:\Projects\alab-remix-2\node_modules\@remix-run\node\dist\upload\fileUploadHandler.js:144:14)
at W:\Projects\alab-remix-2\node_modules\@remix-run\node\dist\upload\fileUploadHandler.js:131:12
...
 at async requestHandler (W:\Projects\alab-remix-2\node_modules\@remix-run\server-runtime\dist\server.js:104:18)
at async nodeHandler (W:\Projects\alab-remix-2\node_modules\@remix-run\dev\dist\vite\plugin.js:781:27)     
at async W:\Projects\alab-remix-2\node_modules\@remix-run\dev\dist\vite\plugin.js:784:15
@markdalgleish
Copy link
Member

Could you share a minimal reproduction?

@romanpeganov
Copy link
Author

I created a new Remix-Vite project with minimal reproduction and the file download was successful.
It turned out to be in the file vite.config.ts of my project there was no installation of global variables:

import { installGlobals } from "@remix-run/node";

installGlobals();

I apologize for the concern. I hope this information is useful to someone.

@romanpeganov
Copy link
Author

Issue is completed

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

No branches or pull requests

2 participants