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

Packages error - 'process is not defined' #225

Closed
gabriGutiz opened this issue Mar 4, 2024 · 7 comments
Closed

Packages error - 'process is not defined' #225

gabriGutiz opened this issue Mar 4, 2024 · 7 comments

Comments

@gabriGutiz
Copy link

gabriGutiz commented Mar 4, 2024

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
Copy link
Member

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
Copy link
Member

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

@gabriGutiz
Copy link
Author

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
Copy link

rogigs commented Mar 14, 2024

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
Copy link

mirazib71 commented Apr 27, 2024

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

@jonchurch
Copy link
Member

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
Copy link
Author

gabriGutiz commented Apr 30, 2024

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!

@pillarjs pillarjs locked and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants