Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-extraneous-import: doesn't work if package main file is not resolved #148

Closed
beshanoe opened this issue Jan 29, 2019 · 2 comments
Closed

Comments

@beshanoe
Copy link

beshanoe commented Jan 29, 2019

I have a monorepo with packages written in typescript. Each package has structure like this:

packages/
  util/
    lib/
    index.ts
    package.json
  cli/
  builder/

package.json structure is following:

{
  "name": "@monorepo/util",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT"
}

when I develop, I use ts-node to run cli package, so I don't need to precompile TS files before executing, ts-node does it for me, also it resolves files correctly, if I run require.resolve('@monorepo/builder') during ts-node run, it returns packages/builder/index.ts.

The problem is that no-extraneous-import's resolver doesn't find index.js until the project is built and therefore doesn't throw an error if I import one monorepo's package to another without mentioning in in the package.json. This particular line is responsible for this bug:

target.filePath != null &&

My question is why does the rule care if the module's main file is resolved or not. I mean, whether the package exists or not is the responsibility of other tools. At least it would be nice to opt-out that behaviour

@mysticatea
Copy link
Owner

Thank you for the report.

Sounds like a bug. You are right.

Would you send a PR?

@beshanoe
Copy link
Author

Probably it's not a bug, just managed to fix the behaviour by setting tryExtensions in the .eslintrc:

"settings": {
    "node": {
      "tryExtensions": [".ts", ".tsx", ".js", ".jsx"]
    }
  },

So it's more of documentation issues, cause docs say there's only one option for this rule https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-extraneous-import.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants