1

Would like to use imports by using absolute/dynamic paths, like

import { GlobalVars } from "utils/GlobalVars.js";

but not like

import { GlobalVars } from "../../utils/GlobalVars.js";

With the help of below code snippet able to follow absolute/dynamic path facility in react

jsconfig.json (Which is created at root level of the project)

{
    "compilerOptions": {
        "baseUrl": "src"
    },
    "include": ["src"]
}

with the same code snippet unable to use absolute paths in NodeJs.

Do we have any other approach to use absolute paths in NodeJs or am i doing any mistake

Bahu
  • 1,516
  • 2
  • 28
  • 49
  • 1
    `webpack.config.js` has a feature : `resolve` where we can give `aliase` to paths. See https://medium.com/@etherealm/getting-rid-of-relative-paths-in-imports-using-webpack-alias-78d4bf15bb42 – Rohit Khanna Jan 21 '21 at 17:48
  • Thank you for the comment, i tried the link which you provided and also these https://stackoverflow.com/questions/27502608/resolving-require-paths-with-webpack, https://medium.com/@sherryhsu/how-to-change-relative-paths-to-absolute-paths-for-imports-32ba6cce18a5 but it's not working – Bahu Jan 21 '21 at 18:37
  • neither one of your examples uses an absolute path. – madflow Jan 21 '21 at 19:37

0 Answers0