Can NODE_PATH be set in .env?
Closed this issue · 1 comments
ivan-kleshnin commented
Hi. Is it possible to declare NODE_PATH
constant in .env
?
When I run my script with NODE_PATH=./ node myscript.js
it resolves absolute local imports just fine.
But when I'm doing this:
# .env
export NODE_ENV=./
// myscript.js
import "./backend/env.js"
import "common/shims.js"
// backend/env.js
import nvar from "nvar"
nvar({
override: "empty",
})
console.log(process.env.NODE_PATH) // "./"
I'm getting correct value in process.env.NODE_PATH
but import "common/shims"
still throws Cannot find module
.
It behaves like if Node required NODE_PATH
to be set before anything else, yet I see that people do put their NODE_PATH
in .env
files and it somehow works for them 😮
Could you help my to clarify this moment?
ivan-kleshnin commented
Found a solution:
nvar({
override: "empty",
})
// !!! magic line
require("module").Module._initPaths()