Comments (5)
They're supported. But there could be a bug. What's the issue you're seeing?
A common pitfall is that the main
or subpath imports
point to ignored/dist files, which aren't added to the analysis by Knip.
from knip.
I have the following setup:
files:
package.json
📁 src
|__ firstFile.js
|__ secondFile.js
package.json
{
"name": "knip-issue-576",
"version": "1.0.0",
"type": "module",
"scripts": {
"knip": "knip",
"main": "node \"./src/firstFile.js\""
},
"imports": {
"#*": "./*"
},
"devDependencies": {
"@types/node": "^20.11.30",
"knip": "^5.6.1",
"typescript": "^5.4.3"
}
}
src/firstFile.js
import secondFile from "#src/secondFile.js";
console.log(secondFile.text);
src/secondFile.js
const text = "hello world!";
export default { text };
Output when running npm run knip
:
Unused files (1)
src/secondFile.js
Unresolved imports (1)
#src/secondFile.js src/firstFile.js:1:23
Expected output:
✂️ Excellent, Knip found no issues.
I am currently working around this by adding the following knip.json
config file, but it would be better if it wasn't needed:
knip.json
{
"paths": { "#*": ["./*"] }
}
from knip.
I remember #*
and #/*
aren't valid aliases. Maybe TypeScript accepts them, but the Node.js runtime does not.
Can you try valid aliases and see if that works better?
Also see:
- https://nodejs.org/api/packages.html#subpath-imports
- https://www.webpro.nl/articles/using-subpath-imports-and-path-aliases
from knip.
Are you sure it isn't just #/*
that's invalid?
I've been using #*
in some pretty large-scale Node.js applications without TypeScript and never had any problems with it.
I've also read through both of the reference links you provided and found no indication of #*
being invalid either.
You can run the npm run main
script in the setup from the example above (which has no .ts or .tsconfig files and only references typescript in the package.json due to Knip's peer dependency) and see that Node.js outputs the "hello world" string as expected... as opposed to the TypeError [ERR_INVALID_MODULE_SPECIFIER]
that shows up when we use an invalid alias
from knip.
Are you sure it isn't just
#/*
that's invalid?
No, I haven't actually used this alias myself.
Could you please provide a reproduction of the issue, so I can look into it. I don't have the bandwidth to set that up myself for everyone.
from knip.
Related Issues (20)
- Arguably terrible enum identifiers causes breakage. HOT 1
- Detect `yarn.config.cjs`
- Nx plugin doesn't look in `package.json`
- Nx plugin doesn't detect binaries without explicit executor
- File index.js and extensions that are omitted by default HOT 4
- storybook: @storybook/builder-vite is incorrectly listed as unused devDependencies HOT 1
- False positive for dev dependency listed in jest config HOT 1
- Add support for Ionic / enhance the capacitor plugin HOT 7
- Consider the file in package.json types not to be unused HOT 3
- Add a brief page to the documentation showing how to use on CI HOT 2
- `peerDependency` range conflicts with `typescript` beta releases
- Module Resolution Issues Across Multiple Workspaces with TSConfig Paths
- knip generates undesired code near to console.log lines HOT 2
- Respect .git/info/exclude in addition to .gitignore HOT 10
- Autofix - remove trailing commas HOT 4
- TypeScript Namespace - Unsed exported constants not detected HOT 7
- Lazy imports not accessible when accessed by key HOT 10
- Workspaces no longer correctly identified since 5.10 HOT 6
- Issue a warning or fail if a specific file given as an entry point does not exist HOT 1
- Marked as unused if used only in Vue <template> HOT 11
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.