Code Monkey home page Code Monkey logo

Comments (5)

webpro avatar webpro commented on September 24, 2024

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.

lucasrmendonca avatar lucasrmendonca commented on September 24, 2024

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.

webpro avatar webpro commented on September 24, 2024

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:

from knip.

lucasrmendonca avatar lucasrmendonca commented on September 24, 2024

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.

webpro avatar webpro commented on September 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.