While installing, I got 'ReferenceError: require is not defined"

During installation, I got following error msg

ReferenceError: require is not defined
    at file:///var/www/frappe-bench/apps/raven/frontend/tailwind.config.js:193:12
    at ModuleJobSync.runSync (node:internal/modules/esm/module_job:367:35)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:325:47)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1392:24)
    at Module._compile (node:internal/modules/cjs/loader:1525:5)
    at Object..js (node:internal/modules/cjs/loader:1680:16)
    at Module.load (node:internal/modules/cjs/loader:1328:32)
    at Function._load (node:internal/modules/cjs/loader:1138:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)

Node.js v23.0.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Command failed: yarn build

The same error msgs are created for various apps that uses ‘require’ instead of ‘import’, I think.

A little update

I now am stuck at this screen.

bench get-app https://github.com/frappe/drive.git
Getting drive
$ git clone https://github.com/frappe/drive.git  --depth 1 --origin upstream
Cloning into 'drive'...
remote: Enumerating objects: 512, done.
remote: Counting objects: 100% (512/512), done.
remote: Compressing objects: 100% (444/444), done.
remote: Total 512 (delta 76), reused 325 (delta 47), pack-reused 0 (from 0)
Receiving objects: 100% (512/512), 12.53 MiB | 13.59 MiB/s, done.
Resolving deltas: 100% (76/76), done.
Ignoring dependencies of https://github.com/frappe/drive.git. To install dependencies use --resolve-deps
Installing drive
$ /var/www/frappe/env/bin/python -m pip install --quiet --upgrade -e /var/www/frappe/apps/drive
$ yarn install --check-files
yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
$ cd frontend && npm install
(node:129484) ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
⠙^C
Aborted!

Have tested with main branch as well as the dev branch, but both are in the same situation. I also tested with lower version Node/npm, but then upgrade it to the latest (v23), but I still have the same error.

This first one, is an issue with Raven not Drive, they’re not the same error/warning.

This second one, you could’ve let this second one finish instead of aborting it. The require() is only a warning not an error. I’ve validated this on node 18, 20, (recommended) and 23 for your instance.

Regarding the main vs develop. I suggest sticking to main, so bench get-app drive --branch main. Avoid using different versions than the recommended ones if you can help it, for database and runtimes especially.

This is fixed now.

@arjun_c thank you and sorry about the mix btwn drive / raven.
for drive, the issue got resolved with node 18.20.4

I didn’t abort it. It just got stuck there for a long time. I will revert back to main version of drive.

and @nikkothari22 thank you for the update. I can see that it is now with ‘import’.

Interesting, will investigate this further.

main version worked smoothly. :+1: