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

Invalid eslint error for "import/no-extraneous-dependencies" when it's reference self #2430

Open
lygstate opened this issue Apr 7, 2022 · 12 comments

Comments

@lygstate
Copy link

lygstate commented Apr 7, 2022

{
  "name": "@ts/deferred",
  "version": "1.0.0",
  "description": "The deferred library implemented in Typescript",
  "license": "MIT",
  "scripts": {
    "build": "yarn run build:esm && yarn run build:cjs && yarn run build:types",
    "build:esm": "tsc -p tsconfig.mjs.json",
    "build:cjs": "tsc -p tsconfig.cjs.json",
    "build:types": "tsc -p tsconfig.types.json",
    "test": "jest --config ../../jest.config.ts"
  },
  "module": "./dist/mjs/index.js",
  "main": "./dist/cjs/index.js",
  "types": "./dist/types/index.d.ts"
}

Error:

[{
	"resource": "/c:/work/tslibs/packages/deferred/test/deferred-in-js.test.js",
	"owner": "eslint",
	"code": {
		"value": "import/no-extraneous-dependencies",
		"target": {
			"$mid": 1,
			"external": "https://github.com/import-js/eslint-plugin-import/blob/v2.26.0/docs/rules/no-extraneous-dependencies.md",
			"path": "/import-js/eslint-plugin-import/blob/v2.26.0/docs/rules/no-extraneous-dependencies.md",
			"scheme": "https",
			"authority": "github.com"
		}
	},
	"severity": 8,
	"message": "'@ts/deferred' should be listed in the project's dependencies. Run 'npm i -S @ts/deferred' to add it",
	"source": "eslint",
	"startLineNumber": 1,
	"startColumn": 22,
	"endLineNumber": 1,
	"endColumn": 45
}]
@ljharb
Copy link
Member

ljharb commented Apr 7, 2022

Self-reference only works with the "exports" or "imports" field, which this plugin doesn't yet support.

You shouldn't be able to self-require the package otherwise.

@jacobrask
Copy link

Yarn workspaces, and I assume npm and pnpm workspaces too, installs all local packages to node_modules/package-name.

In the tests of a package I want to reference the built package. The file

packages/my-package/__tests__/my-package.test.js

imports my-package (resolving to packages/my-package/dist/index.js), which triggers import/no-extraneous-dependencies.

@ljharb
Copy link
Member

ljharb commented May 6, 2022

@jacobrask yes, in that case it should Just Work. If it doesn't, and you can run the node repl and require.resolve(specifier) works, then please file a separate issue.

@ljharb

This comment was marked as resolved.

@ljharb
Copy link
Member

ljharb commented Jul 18, 2022

Self-referencing only works in node via the "exports" or "imports" fields, which this package (via resolve) does not yet support - but will hopefully, soon.

It should not be expected to work otherwise.

@rhangai
Copy link

rhangai commented Jul 18, 2022

In my case, since it is a custom rollup project, it works as expected, but I get your point, deleting my comments to prevent bad practices/habits. 👍

@rmarkins-godaddy
Copy link

Self-referencing only works in node via the "exports" or "imports" fields, which this package (via resolve) does not yet support - but will hopefully, soon.

It should not be expected to work otherwise.

@ljharb Do we have an idea on when this will be added to this plugin? or waiting on someone to contribute this?

@ljharb
Copy link
Member

ljharb commented Oct 18, 2022

@rmarkins-godaddy it needs to be added to resolve, and i'm working on the reverse algorithm for list-exports first to serve as test fixtures.

Since it's a best practice to make packages backwards-compatible to pre-exports node, i'd hope this feature gap is minimally impactful in the meantime.

@lxsmnsyc
Copy link

lxsmnsyc commented Dec 5, 2023

What's the status on this? It's already been a year and it seems to be still unsolved. I would have to guess that resolve still doesn't support it?

@ljharb
Copy link
Member

ljharb commented Dec 5, 2023

@lxsmnsyc it's been 4 years since node shipped "exports", and yes, resolve still doesn't support it.

@lxsmnsyc
Copy link

lxsmnsyc commented Dec 5, 2023

@ljharb how is resolve different from, say, resolve.exports package? or is it possible to transition to it?

@ljharb
Copy link
Member

ljharb commented Dec 5, 2023

There's a lot of functionality we'd need - in particular, we'd need the ability to lint against a particular version of node's support, and nothing in the ecosystem provides that (resolve, however, will).

No matter how much longer it takes, I'm unlikely to switch from resolve.

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

No branches or pull requests

6 participants