Skip to content

Usage of NODE_PATH in react-testing-library with create-react-app v4 #693

Closed
@ClementParis016

Description

@ClementParis016

Hello 👋

create-react-app no longer supports usage of NODE_PATH in .env since v4:

Removed typescript flag and NODE_PATH support

We've removed the deprecated typescript flag when creating a new app. Use --template typescript instead. We've also dropped deprecated NODE_PATH flag as this has been replaced by setting the base path in jsconfig.json.

So I think we should update this part of the docs to reflect that:

### Jest and Create React App
If your project is based on top of Create React App, to make the `test-utils`
file accessible without using relative imports, you just need to create a `.env`
file in the root of your project with the following configuration:
```
// Create React App project structure
$ app
.
├── .env
├── src
│ ├── utils
│ │ └── test-utils.js
```
```
// .env
// example if your utils folder is inside the /src directory.
NODE_PATH=src/utils
```

My project doesn't run on CRA v4 yet so I can't tell how exactly what the alternative should be, but I will look into it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions