Why does VS Code “Go to definition” feature not work for this custom NPM package?

梦想的初衷 提交于 2020-01-25 07:26:27

问题


I have created a custom NPM package:

NPM: https://www.npmjs.com/package/cartesian-composition

GitHub: https://github.com/tonix-tuft/cartesian-composition

You can install it through this NPM command:

npm install --save js-utl cartesian-composition

And use it like this in another project:

import cartesianComposition from "cartesian-composition";

const a = (...res) => `a(${res.join(", ")})`;
const b = (...res) => `b(${res.join(", ")})`;
const c = (...res) => `c(${res.join(", ")})`;
const d = (...res) => `d(${res.join(", ")})`;
const e = (...res) => `e(${res.join(", ")})`;
const f = (...res) => `f(${res.join(", ")})`;
const g = (...res) => `g(${res.join(", ")})`;
const h = (...res) => `h(${res.join(", ")})`;
const i = (...res) => `i(${res.join(", ")})`;

const res = cartesianComposition(
  [a, b, c],
  [[cartesianComposition.OPTIONAL], d, e, f, g],
  [h, [[cartesianComposition.OPTIONAL], i]]
)(1, 2, 3);

console.log(res);

It works pretty well, the only thing is that if I go to the import line:

import cartesianComposition from "cartesian-composition";

...

and try to Cmd + click or right-click and click on "Go to definition", VS Code does not send me to the source code of the package. Whereas this works for other packages, not created by me, so I guess there's something I am missing.

Here is the package.json of the cartesian-composition package:

{
  "name": "cartesian-composition",
  "version": "1.0.0",
  "description": "A higher order function to compose functions through cartesian composition.",
  "keywords": [
    "composition",
    "functional-programming",
    "composite",
    "cartesian-composition"
  ],
  "author": "Anton Bagdatyev (Tonix-Tuft)",
  "license": "MIT",
  "main": "./dist/index.js",
  "module": "./src/index.js",
  "repository": {
    "type": "git",
    "url": "https://github.com/tonix-tuft/cartesian-composition.git"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "watch": "WEBPACK_ENV=watch webpack --progress --colors --watch",
    "build": "WEBPACK_ENV=build webpack"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.9.0",
    "@typescript-eslint/parser": "^2.9.0",
    "eslint": "^6.7.2",
    "js-utl": "^1.2.0",
    "terser-webpack-plugin": "^1.4.1",
    "typescript": "^3.7.2",
    "uglifyjs-webpack-plugin": "^2.2.0",
    "webpack": "^4.41.2",
    "webpack-cli": "^3.3.10"
  },
  "peerDependencies": {
    "js-utl": "^1.2.0"
  },
  "bugs": {
    "url": "https://github.com/tonix-tuft/cartesian-composition/issues"
  },
  "homepage": "https://github.com/tonix-tuft/cartesian-composition#readme"
}

I bundle it using Webpack you can check my config on the GitHub repo or ask me to include it here if it's needed.

The package itself consists of a single index.js file in src/.

How can I make VS Code to go to cartesian-composition's source code when I Cmd + click on it?

Thank you.

来源:https://stackoverflow.com/questions/59128917/why-does-vs-code-go-to-definition-feature-not-work-for-this-custom-npm-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!