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.

Support absolute paths with packages/ folder

See original GitHub issue

We’ve been using Lerna in Create React App, and I really like its approach. I think we should support a similar workflow (even without Lerna itself) for the “absolute paths” feature.

I imagine it working like this:

  • In addition to src, you can create a special top-level folder called packages.
  • Inside packages, you can create folders like app, stuff, lol, and they all “see” each other so you can import things from app/whatever.js or lol/wow.js. You can also import any packages from src (but not vice versa). The entry point is still src/index.js.
  • We won’t add any magic handling that breaks Node resolution mechanism. Instead, whenever you npm start, npm test, or npm run build, we will run a utility that creates symlinks from node_modules of the root project to every folder in packages. It reports a hard error if there is a conflict. This means the authors can add server rendering after ejecting without scratching their heads, and that all the tooling assuming Node resolution mechanism keeps working.
package.json
public/
src/
  index.js # can import app/banana.js or harry-potter/wand.js
packages/
  app/
    banana.js # can import harry-potter/wand.js
  harry-potter/
    wand.js # can import app/banana.js
node_modules/
  app -> packages/app
  harry-potter -> packages/harry-potter
  other-deps

Am I missing why this would be a bad idea?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:47
  • Comments:86 (24 by maintainers)

github_iconTop GitHub Comments

57reactions
kasperpeulencommented, Sep 28, 2016

I think it may be a good idea to consider teaching people this pattern:

screen shot 2016-09-28 at 20 06 28

This seem to not only work with create-react-app, but everywhere. You don’t need any symlinks or whatever.

33reactions
will-stonecommented, Feb 10, 2017

Glad I stumbled upon this. I’ve put NODE_PATH=src/ in my .env file and now I can use this import Button from 'components/Button' from any file. Thank-you all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to import a folder with absolute path as package?
The path is app/base/admin/crud/__init__.py . I want to import an entire folder as a package like this: import app.base ...
Read more >
Working Directories, Absolute and Relative Paths ...
An absolute path is a path that contains the entire path to the file or directory that you need to access. This path...
Read more >
Importing with Absolute Paths in JavaScript/TypeScript using ...
How to use absolute paths in JavaScript and TypeScript to improve your import statements, using the right webpack configuration.
Read more >
Java File Path, Absolute Path and Canonical Path
Let's see different cases of the file path in java with a simple program. package com.journaldev.files; import java.io.File; import java.io.
Read more >
Paths explained: Absolute, relative, UNC, and URL—Help
After navigating to this directory, a relative path will use D:\Data\Shapefiles\Soils as the current directory (until you navigate to a new directory, at...
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