When I import node:process
it works fine. However, when I try to require the same, it gives an error.
This works fine:
import process from 'node:process';
But when I try to require the same, it throws an error:
const process = require('node:process');
Error: Cannot find module 'node:process'
I am curious as to what is the difference between process
, which works in both, commonjs and module, vs node:process
.
Also, a follow-up, I am using webpack to bundle my js, and I discovered this error when I tried to run my bundled code and realised, that chalk
imports node:process
, node:os
and node:tty
. How do I solve that now?
'process'
will still load the native built-in module and ignore the one in node modules directory. But if the nodejs runtime (or some other JS runtime) didn't have theprocess
module built-in, then it would load it from the node modules directory if it understands commonjs/ES module standards. – Thermocline