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.

import/no-unresolved does not support multiple nested package.json

See original GitHub issue

Folder / file structure:

.
├── .eslintrc
├── package.json // Package 1
├── src
│   └── package.json // Package 2
│   ├── components
│   │   └── Foo.jsx

Content of Package 2:

{
  "name": "src"
}

This enables me to import Foo.jsx like so (from anywhere):

import Foo from 'src/components/Foo';

This node resolution behaviour is standard as far as I know.

eslint-plugin-import is not able to resolve my files:

  5:23  error  Unable to resolve path to module 'src/components/Foo'  import/no-unresolved

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
eightyfivecommented, Jan 29, 2019

Ok thanks.

A better alternative (to my previous solution) is to use Yarn workspaces:

// ./package.json (main)
{
  "private": true,
  "workspaces": ["src"]
}

Note: ./src/package.json remains unchanged, see https://github.com/benmosher/eslint-plugin-import/issues/1272#issue-403798133.

This does not require to install/re-install the local src folder after every change.

And it works with eslint-plugin-import plugin. It does not work. Use relative paths as suggested by @ljharb.

More details here (Stackoverflow).

2reactions
eightyfivecommented, Jan 29, 2019

I threw a small Node project on my laptop and @ljharb is right, it does not seem to work outside of node_modules.

The fact that it works when bundling a RN app, must be RN specific then.

I’ll find an alternative, thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

import/no-unresolved does not support multiple nested ...
This enables me to import Foo.jsx like so (from anywhere):. import Foo from 'src/components/Foo';. This node resolution behaviour is standard as ...
Read more >
The best way to run npm install for nested folders?
I think the most idiomatic thing is to have a single package.json file at the to of your project. · One idea would...
Read more >
package.json - npm Docs
This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just a...
Read more >
Modules: Packages | Node.js v19.3.0 Documentation
Introduction#. A package is a folder tree described by a package.json file. The package consists of the folder containing the package.json file and...
Read more >
An In-Depth Explanation of package.json's Dependencies
This article describes different types of dependencies in package.json ... Marking a peer dependency as optional ensures npm will not emit a warning...
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