eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

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

Open lygstate opened this issue 2 years ago • 6 comments

{
  "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
}]

lygstate avatar Apr 07 '22 17:04 lygstate

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.

ljharb avatar Apr 07 '22 18:04 ljharb

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.

jacobrask avatar Apr 10 '22 19:04 jacobrask

@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 avatar May 06 '22 04:05 ljharb

@rhangai bundleDependencies is for publishing packages that vendor in node_modules - i'd suggest avoiding it.

ljharb avatar Jul 18 '22 15:07 ljharb

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 avatar Jul 18 '22 17:07 ljharb

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. :+1:

rhangai avatar Jul 18 '22 17:07 rhangai

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?

rmarkins-godaddy avatar Oct 18 '22 05:10 rmarkins-godaddy

@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.

ljharb avatar Oct 18 '22 05:10 ljharb

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?

lxsmnsyc avatar Dec 05 '23 05:12 lxsmnsyc

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

ljharb avatar Dec 05 '23 05:12 ljharb

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

lxsmnsyc avatar Dec 05 '23 05:12 lxsmnsyc

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.

ljharb avatar Dec 05 '23 05:12 ljharb