analogjs / analog

The fullstack meta-framework for Angular. Powered by Vite and Nitro
https://analogjs.org
MIT License
2.5k stars 240 forks source link

Error with 'require is not defined' in Node.js v19.8.1 #343

Closed mohammadraufzahed closed 1 year ago

mohammadraufzahed commented 1 year ago

Please provide the environment you discovered this bug in.

Device and Software Specifications

Which area/package is the issue in?

create-analog

Description

After installing Node.js v19.8.1 and running the '@analogjs/platform' server, an error occurs with the message "require is not defined" in the 'xhr2' module. This error is triggered in the 'xhr2.js' file at line 119, causing a reference error. This issue prevents the server from running correctly and accessing the endpoints.

Please provide the exception or error you saw

Node.js version v19.8.1 detected.
Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/.

The '@analogjs/platform' successfully started.
The server endpoints are accessible under the "/api" path.
  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

ReferenceError: require is not defined
    at /node_modules/.pnpm/xhr2@0.2.1/node_modules/xhr2/lib/xhr2.js:119:3
    at /node_modules/.pnpm/xhr2@0.2.1/node_modules/xhr2/lib/xhr2.js:1244:4
    at instantiateModule (file:///W:/Workspace/Junk%20Repos/analog-project/node_modules/.pnpm/vite@4.0.3_@types+node@18.15.11_less@3.12.2_stylus@0.55.0/node_modules/vite/dist/node/chunks/dep-0bae2027.js:52198:15)

Node.js v19.8.1

Other information

Reproduce

  1. Install Node.js v19.8.1 on the 'MohammadRaufzah' device with the provided specifications.
  2. Install 'analog' version 0.2.3 using 'pnpm' version 8.2.0 with Angular16 as the chosen option.
  3. Start the '@analogjs/platform' server using the command analog start.
  4. Access the server endpoints under the "/api" path on the local host (http://localhost:5173/).

I would be willing to submit a PR to fix this issue

brandonroberts commented 1 year ago

Thanks @mohammadraufzahed. What fix are you proposing?

kpetravicius commented 1 year ago

Same error with Node version: 16.16.0

Changing vite config plugins section and disabling ssr option kinda resolves application start error. From: plugins: [analog()], to: plugins: [analog({ ssr: false })],

brandonroberts commented 1 year ago

Node versions 16.17.0 and 18.13.0+ have been verified as working

mohammadraufzahed commented 1 year ago

I tested with node 18 but it faild

julianstephens commented 1 year ago

Getting the same issue on Node 18.16

cSparkle commented 1 year ago

Same error with Node version: 16.16.0

Changing vite config plugins section and disabling ssr option kinda resolves application start error. From: plugins: [analog()], to: plugins: [analog({ ssr: false })],

This solution worked for me on Node 18.16 using Angular 16 pre-release

goetzrobin commented 1 year ago

Might be related to and resolved by this effort: https://github.com/angular/angular/pull/50247

JeanMeche commented 1 year ago

Hi, I can confirm that angular/angular#50247 will allow to drop the usage of xhr2 (as a developer preview though)

brandonroberts commented 1 year ago

Try this with the latest release and see if its still an issue