question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create react app with absolute imports (`NODE_PATH`)

See original GitHub issue

Question

Description

Reading #140 I get the impression that NODE_PATH in .env should be supported.

I’ve gotten a create-react-app until the point of supporting absolute paths. Is there any way to tell docz to use src as NODE_PATH?

Steps to reproduce

I’ve created an example in https://github.com/KATT/create-react-app-docz-test

git clone git@github.com:KATT/create-react-app-docz-test.git
cd create-react-app-docz-test
yarn docz:dev

Error

This dependency was not found:

* components/Logo in ./src/components/App/index.js

Note

The example project works if we revert eaba11.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
spernigotticommented, Oct 17, 2018

Hello @KATT I’ve the same problem. For the moment, I found this solution changing the babel configuration of docz.

First install the babel plugin babel-plugin-module-resolver

npm install --save-dev babel-plugin-module-resolver

Next, create (if you don’t have it) the docz configuration file named doczrc.js and add:

module.exports = {
  modifyBabelRc(babelrc) {
    return {
      ...babelrc,
      plugins: [
        ...babelrc.plugins,
        ['module-resolver', {
          root: ['./src']
        }]
      ]
    };
  }
};

You can use the variable process.env.NODE_PATH instead of the string './src'.

2reactions
pedronauckcommented, Dec 17, 2018

Launched on v0.13.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Absolute imports with Create React App | by David Gilbertson
With the release of Create React App 3, we now have the ability to use absolute import paths, without ejecting. If you're reading...
Read more >
Absolute Path Imports · Issue #4928 · facebook/create-react-app
According to the links below I understand .env with NODE_PATH=src in it, allows the react app to take advantage of Absolute Path Imports...
Read more >
Absolute imports in Create React App - DEV Community ‍ ‍
Absolute imports can help you make that code a lot cleaner, more readable and manageable. We want to be able to transform our...
Read more >
Using Absolute Imports in React TypeScript Projects
Importing using relative paths can get pretty ugly quickly. Learn how to use absolute paths to make importing files easier.
Read more >
Absolute Imports: React and Typescript - Stack Overflow
I have a React app bootstrapped using create-react-app and typescript. As the application has grown, (goal) I would like to implement absolute ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found