Laravel migration to mix drops invalid NODE_OPTIONS env variable: --openssl-legacy-provider is not allowed

Viewed 3634

When I run yarn run dev it compiles without any issues, but when I run the yarn run prod I got the following error:

āœ– Mix
  Compiled with some errors in 21.47s

ERROR in /js/app.js
/js/app.js from Terser plugin
Initiated Worker with invalid NODE_OPTIONS env variable: --openssl-legacy-provider is not allowed in NODE_OPTIONS
Error [ERR_WORKER_INVALID_EXEC_ARGV]: Initiated Worker with invalid NODE_OPTIONS env variable: --openssl-legacy-provider is not allowed in NODE_OPTIONS
    at new NodeError (node:internal/errors:371:5)
    at new Worker (node:internal/worker:194:13)
    at ExperimentalWorker.initialize (/var/www/dashboard-v2/node_modules/jest-worker/build/workers/NodeThreadsWorker.js:149:20)
    at new ExperimentalWorker (/var/www/dashboard-v2/node_modules/jest-worker/build/workers/NodeThreadsWorker.js:145:10)
    at WorkerPool.createWorker (/var/www/dashboard-v2/node_modules/jest-worker/build/WorkerPool.js:44:12)
    at new BaseWorkerPool (/var/www/dashboard-v2/node_modules/jest-worker/build/base/BaseWorkerPool.js:127:27)
    at new WorkerPool (/var/www/dashboard-v2/node_modules/jest-worker/build/WorkerPool.js:30:1)
    at new Worker (/var/www/dashboard-v2/node_modules/jest-worker/build/index.js:167:26)
    at getWorker (/var/www/dashboard-v2/node_modules/terser-webpack-plugin/dist/index.js:391:9)
    at /var/www/dashboard-v2/node_modules/terser-webpack-plugin/dist/index.js:494:41
    at next (/var/www/dashboard-v2/node_modules/terser-webpack-plugin/dist/utils.js:90:7)
    at Array.forEach (<anonymous>)
    at /var/www/dashboard-v2/node_modules/terser-webpack-plugin/dist/utils.js:93:26
    at new Promise (<anonymous>)
    at throttleAll (/var/www/dashboard-v2/node_modules/terser-webpack-plugin/dist/utils.js:62:10)
    at TerserPlugin.optimize (/var/www/dashboard-v2/node_modules/terser-webpack-plugin/dist/index.js:651:34)

webpack compiled with 1 error
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
root@fe7a5c6ae6f9:/var/www/dashboard-v2# 

I have deleted all node_modules installed all from 0, updated all to the latest still the same. Any idea how to resolve this isue?

2 Answers

Node v17.x is giving this issue.

I suggest you switch to v16. On Linux it's easy, you just reselect the older version on your system:

sudo n

It will show you the older versions on the system if any which you can switch to. If you don't find any v16 you'll have to manually install it.

See https://ostechnix.com/how-to-manage-nodejs-versions-with-n-in-linux/

Did try many things and one option was to revert node to v16 as suggested by usernotnull, but wanted to find what is the real issue.

It seams that if it is php 7.4 or less then it try to load dependencies, when upgraded php to 8 and on cli too the error was gone.

Also upgrading from laravel 7 to 8, need to update the dependencies.

After upgrade this is also a good to do so no cache or view left:

php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan view:clear
php artisan route:clear

Since then all works and not geting the above error.

Related