pillarjs / send

Streaming static file server with Range and conditional-GET support
MIT License
796 stars 188 forks source link

Packages error - 'process is not defined' #225

Closed gabriGutiz closed 6 months ago

gabriGutiz commented 6 months ago

After adding implementation for canActivate in angular routing, the following errors started:

Uncaught ReferenceError: process is not defined processError

For that I found two "solutions":

1 Add this code as script to index.html file: <script>window.process = { env: { NODE_ENV: 'production' } };</script> That I don't really like

2 Add a polyfill.ts file:

import * as process from 'process';
window['process'] = process;

Both solutions gives me the error:

Uncaught TypeError: util.inherits is not a function utilError

That I wasn't able to solve.

I have no ideia what is happening and I could not find any solution in the internet. I tested the CanActivateFn and is working fine, but the non authenticated page gives me the errors described.

For context, this is my app.routes.ts:

import { authGuard } from '@core';
import { Routes } from '@angular/router';
import { HomeComponent, LoginComponent, MainComponent, MainHomeComponent, NotFoundComponent } from '@pages';

export const routes: Routes = [
  {
    path: '',
    title: 'ReservationApp',
    canActivate: [authGuard],
    pathMatch: 'full',
    component: MainComponent,
    children: [
      { path: '', component: MainHomeComponent }
    ]
  },
  {
    path: '',
    children: [
      { path: '', redirectTo: 'login', pathMatch: 'full' },
      { path: 'login', title: 'Log in', component: LoginComponent },
      { path: '**', component: NotFoundComponent }
    ]
  }
];

When going to root page being not authenticated the described errors occur. I'm using Angular 17, node 20.11.1 and send 0.18.0.

jonchurch commented 6 months ago

Your issue is due to send being a package which is meant to stream files from the filesystem of a server to a client.

The APIs it relies on to do so are Node specific, and not available in the browser where your angular client is running.

jonchurch commented 6 months ago

The specific APIs your errors are from are Node's process and util

gabriGutiz commented 6 months ago

Your issue is due to send being a package which is meant to stream files from the filesystem of a server to a client.

Understood! Thanks for the clarification!

The APIs it relies on to do so are Node specific, and not available in the browser where your angular client is running.

Any idea on how to solve it? Or should I open an issue in any other package repo?

rogigs commented 6 months ago

I'm having the same issue, my project was working correctly in the last days but today when I runned the project it broken. Any solution ? @gabriGutiz @jonchurch

mirazib71 commented 4 months ago

I'm getting the same error. Any solution? @gabriGutiz @jonchurch

jonchurch commented 4 months ago

I haven't seen anything which indicates this error is coming from using the package as intended. If you can create a minimum repro then please open a new isue with a reproducible example I can run.

There have been no changes to this package which would introduce this error, so I do not expect it to be an issue with send but instead an issue of using the package in a browser where Node's process global is not (and shoult not) be available.

locking

gabriGutiz commented 4 months ago

Sorry for the late response! I was able to solve the problem in my project, but I'm not sure the real reason.

I recreated the error in this repo, in the main branch the error occurs and in the problem-solved branch, the error is solved.

The file auth.services.ts inside core module is the one creating the error when the @core (a path created) is imported inside app.route.ts. By removing this file or removing the import of @core on app.route.ts, the problem stops.

I didn´t really understood this error, but like @jonchurch said I don´t believe this is a send package error. I also created a stack overflow question here at the time.

Hope this helps, @rogigs and @mirazib71!