Comments (9)
Any chance you could create a reproduction of the issue or add a failing case to one of the test fixtures?
And what's the first version of Knip this fails in for you?
from knip.
It stopped working after 5.16.0. Here's a minimal reproduction:
-
npm init -y
-
entry.ts
require("./child");
-
child.ts
function foo() {} foo();
-
knip.jsonc
{ "$schema": "https://unpkg.com/knip@5/schema.json", "entry": ["./entry.ts"] }
-
Tests:
$ npx [email protected] ✂️ Excellent, Knip found no issues. $ npx [email protected] Unused files (1) child.ts $ npx [email protected] Unused files (1) child.ts
I couldn't reproduce it with .js
files, so maybe that's a hint.
from knip.
I couldn't reproduce it with
.js
files, so maybe that's a hint.
It is. Isn't it odd to require()
ts files without an extension? It's not that common, I wonder what tooling/bundler we're using here? And/or what TS config settings?
from knip.
Hmm I don't think it's unusual. Using tsc and running the output with node was the default basic Node + TypeScript setup (on the backend) until pretty recently.
I suppose using require
with that setup is perhaps uncommon, as tsc does compile import statements for CJS. The case I ran into was using an entrypoint with require('reflect-metadata'); require('./app');
(I was able to change the knip entry as a workaround).
from knip.
I really need an actual reproduction of the issue. The basics work, I just added 0c56610, perhaps its specific TS config settings?
from knip.
Does my previous reproduction not work? That was without any tsconfig in the directory at all – just those three files and the default package.json
from npm init -y
from knip.
Copy-pasting something here is not a reproduction. No tsconfig.json
is most likely the problem. In isolation, why would you expect that to work? Without context I don't understand the situation/use case here.
from knip.
I was trying to make it as minimal as possible .. wouldn't tsconfig.json
just imply some default settings anyway?
Here's my initial reproduction with a bare tsconfig.json
added; it doesn't seem to make a difference to the knip output: https://codesandbox.io/p/devbox/knip-issue-681-xkv92z
I'm not sure I understand why you wouldn't expect that to work? It's a valid program that can be run via tsc
and then node
on the output. I added those scripts to the sandbox too.
from knip.
Thanks for the reproduction.
The underlying issue is that require()
uses node dist/entry.js
from the package.json#main
as a starting point. And dist/*.js
is also part of the project files by default, you probably don't want that.
So my recommendation would be to split up src
and dist
directories, eg:
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"entry": ["src/entry.ts"],
"project": ["src/*.ts"],
}
Not sure if this also is the "fix" for OP, but based on this repro I think the refactoring I did more reveals an issue in cases like this than that it introduces a regression. That split is also better for performance, as Knip does/should not wander off into compiled build artifacts.
from knip.
Related Issues (20)
- False positives on Unresolved paths (repro in issue) HOT 3
- Namespace created from exports reporting that the exports are unused when using namespace imports HOT 5
- Report unnecessary exception tags as errors HOT 4
- graphql-codegen plugin doesn't handle plugins with plugin-specific config HOT 1
- False positives on Github CI with binaries + postcss inconsistency HOT 3
- False negatives in unused exports HOT 2
- Using Knip with `vite.config` HOT 1
- False negative with multiline exports HOT 2
- False negative when re-exporting HOT 4
- Object property enumeration methods used on enum reporting as unused exported enum members HOT 2
- [cypress] add support for cypress-multi-reporter HOT 1
- [jest] support nested jest config files HOT 3
- False positive on unused enum members when using multiple entrypoints + other conditions HOT 3
- False negative when name is used as property HOT 1
- Unused export inside exported namespace not reported HOT 5
- Provide a mechanism to skip reporting on specific unused files HOT 1
- False positives being reported on two packages HOT 1
- Exports previously legitimately reported as unused are no longer reported HOT 1
- All typescript interface files reported as Unused exported types HOT 4
- Unused assets are not reported HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knip.