javascript - Require local node modules with absolute paths doesn't work on Windows -
i'm developing node application several modules. node-application transpiled babel /dist/app
.
this example-structure
. |- main | |- config.js | |- factories | | |- example.js
this config.js:
const ex = require("/main/factories/example");
i launch config.js node dist/app/main/config.js
. resulting error is:
error: cannot find module '/main/factories/example";
however when using const ex = require("./factories/example");
works should.
this problem occurs on windows (testing windows 8.1), both os x , linux fine.
what problem here?
it's other way around, code works expected on windows. /main/factories/example
means c:/main/factories/example
on windows. works on osx/linux because of reason (node_path being set probably). i'd suggest not rely on side effect have working code , don't use relative path either (entirely dependant on working directory), should build absolute path this:
const ex = require(__dirname + "/factories/example");
Comments
Post a Comment