eslint-plugin-import
eslint-plugin-import copied to clipboard
Invalid eslint error for "import/no-extraneous-dependencies" when it's reference self
{
"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
}]
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.
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 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.
@rhangai bundleDependencies is for publishing packages that vendor in node_modules - i'd suggest avoiding it.
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.
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:
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 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.
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 it's been 4 years since node shipped "exports", and yes, resolve
still doesn't support it.
@ljharb how is resolve
different from, say, resolve.exports
package? or is it possible to transition to it?
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
.