2

How I can use absolute path from root and change root, for import components?

import Modal from project/app/src/Components/Modal
import Main from ../../../../Constants

and I want, change root directory to I can import from src

import Modal from Components/Modal
import Main from Constants

I try change workspaces in package.json

"workspaces": [
    "project/app/src/*"
]

or use

"scripts": {
    "start": "NODE_PATH=project/app/src/ webpack-dev-server"
}

but it's not working.

Dan O
  • 6,022
  • 2
  • 32
  • 50
user10053586
  • 79
  • 2
  • 7

2 Answers2

4

.env file with NODE_PATH=src is deprecating.

use jsconfig.json in root dir instead

{
  "compilerOptions": {
    "baseUrl": "./src"
  }
}
Allen Wong
  • 1,162
  • 1
  • 10
  • 15
1

To implement absolute imports in create-react-app First you need to Create a ‘.env’ file at the root level (same level as package.json) then Set an environment variable, ‘NODE_PATH’ to ‘src/’

NODE_PATH=src
sachin mathew
  • 1,432
  • 11
  • 19