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.

2 Answers 2

4

.env file with NODE_PATH=src is deprecating.

use jsconfig.json in root dir instead

{
  "compilerOptions": {
    "baseUrl": "./src"
  }
}
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.